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
 
This will use the contents of the active cell to name the same cell on Sheet2:

Worksheets("Sheet2").Range(ActiveCell.Address).Name = ActiveCell.Value
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi.. sorry for the late response...
Sub Macro4()
'
' Macro4 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



can u put that code in this and post it pls.
 
Upvote 0
dude i figured a way out on this issue.....
all i have to do was install a macro recorder which records keyboard and mouse shortcuts.... then i recorded my keyboard shortcuts of excel in there......
later i start recording the vba macro recorder and hit the playback on the other macro recorder which i installed..... i told the other macro recorder to loop 2000 times... so excel vba recorder is recording this right now and it will take some time...
basically wat i doing is using a free macro recorder inside excel macro recorder. :)
thanks anyways
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,363
Members
449,155
Latest member
ravioli44

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