0

My problem is that I need to execute a Macro only on the marked cell.

The Macro needs to do the following:

Selected cell is formated always for example as 20*20*20 always 3 numbers.

It should copy this text add a " = " before the numbers and output it on another column.

The Code I got until now is:

Sub First()
'
' First Makro
'

'
    Selection.Copy
    Range("G11").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=20*20*20"
    Range("G12").Select
End Sub

I have got this code with the record Macro function

Thanks very much

5
  • Where are you copying and where are you pasting? Your question is not clear. Please exactly explain what are you trying to achieve? Commented Jun 2, 2017 at 7:09
  • @SiddharthRout hi Sir yeah I wanted to be able to select the cell by hand which gets copied to the same row but 2 columns further Commented Jun 2, 2017 at 7:14
  • So you are copying from "E11" in the above code? Commented Jun 2, 2017 at 7:15
  • If yes then see the code that I posted below. You may have to refresh the page to see it Commented Jun 2, 2017 at 7:17
  • @SiddharthRout exactly but i need to be able to select it by hand because sometimes it's for example E17 sometimes e33 and output always need's to be G Column in the Same Row Commented Jun 2, 2017 at 7:18

1 Answer 1

1

@SiddharthRout exactly but i need to be able to select it by hand because sometimes it's for example E17 sometimes e33 and output always need's to be G Column in the Same Row

Is this what you are trying?

Sub Sample()
    Dim wb As Workbook
    Dim ws As Worksheet

    Set wb = ThisWorkbook
    '~~> Replace Sheet1 with the relevant sheet name
    Set ws = wb.Sheets("Sheet1")

     '~~> Check if what the user selected is a valid range
    If TypeName(Selection) <> "Range" Then
        MsgBox "Select a range first."
        Exit Sub
    End If

    '~~> Check if the user has selected a single cell
    If Selection.Cells.Count > 1 Then
        MsgBox "Please select a single cell"
        Exit Sub
    End If

    ws.Range("G" & Selection.Row).Formula = "=" & Selection.Value
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

I'm getting a runtime error when I execute this script
Thanks for your help but I'm getting this error when I execute the macro. Runtime Error 9 and Bound out of Array imgur.com/a/37f39
When you click on deug, which line does it take you to?
I'm getting to the line where I need to input my Map name imgur.com/a/zQjkt
Is that the name of the current worksheet? Also ensure that the sheet is active

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.