Application.Goto Reference (VBA problem when code repeated)

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
here's my 1st code:-

Sub Macro2()
'
' Macro2 Macro
'

'
Selection.Copy
Sheets("Sheet2").Select
Application.Goto Reference:="R1C1"
Selection.End(xlToRight).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet3").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("Sheet1").Select
ActiveCell.Offset(0, 1).Range("A1").Select
End Sub



and i want to do the following on repeating this code:-



Sub Macro4()
'
' Macro4 Macro
'

'
Selection.Copy
Sheets("Sheet2").Select
Application.Goto Reference:="R2C1"
Selection.End(xlToRight).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet3").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("Sheet1").Select
ActiveCell.Offset(0, 1).Range("A1").Select
End Sub

Only difference is in the Application.Goto Reference:="R2C1" in both these macro's


goto reference:='R1C1" in my 1st code is achieved by copying the 'cell range' which is 'A1' in (sheet1) and pasting it in the 'Name Box' of ("sheet2") which gives me R1C1 reference. The problem is that next time when i run this Macro on cell range 'A2' rather than 'A1' from ("Sheet1), and it pastes it in the name box of ("sheet2") just like i did in 1st code, it puts the same reference:="R1C1" as if it is copying A1 and not A2 in the name box ... i need was "R2C1" for 'A2' in the name box of (sheet2).

any help will be appreciated
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Is this what you want?

Code:
Selection.Copy Worksheets("Sheet2").Range("A" & Selection.Row).End(xlToRight)

Generally you don't have to select Range objects to work with them.
 
Upvote 0
Could you explain in English what it is you are trying to achieve? That code looks horribly inefficient - for example you don't really do anything with Sheet2 so what's the point of that bit?
 
Upvote 0
Yes Sir... exactly ... and then paste that in Name Box ... pressing F4
 
Upvote 0
yes kind of but instead of pasting it to the next sheet2 .. i want it to paste it in the 'Name Box' of sheet2... its on left side of formula bar...
thanks
 
Upvote 0
exactly... and its F5 command for name box not F4.. my mistake...

but u got it right

and from there i want to continue to rest of operations in my code
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top