Excel macro to copy cell I4 to active cell

Closed
CS Macro - Oct 6, 2011 at 08:30 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Oct 27, 2011 at 09:27 AM
Hello,

I'm trying to write a macro to copy data in cell I4 to the cell I select (also in column I), but I'm confused between absolute and relative cell referrences. Can anyone help?

Many Thanks





3 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 6, 2011 at 09:43 AM
Hi CS Macro,

Absolute and relative cell references.
When writing a function it is automatically a relative cell reference. Meaning that when you drag the cell, the cell reference will change.
Putting a $ sign in front of the column letter makes it absolute. Meaning that when you drag the cell to the right, the column letter will not change.
Same goes for putting a $ sign in front of the row number.
You can toggle between the available cell references by hitting F4.

Hope that make sense.

To achieve what you want you don't have to think about absolute and relative cell references.
Just use this macro:
Sub test()
Dim x As Integer
x = InputBox("Which row to copy to?")
Range("I4").Copy Cells(x, 9)
Application.CutCopyMode = False
End Sub

Best regards,
Trowa
0
TrowaD,
Please can you repost your response as for some reason I can't read it?
Many Thanks for your help.
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 10, 2011 at 08:48 AM
Strange, but here is my message:

Hi CS Macro,

Absolute and relative cell references.
When writing a function it is automatically a relative cell reference. Meaning that when you drag the cell, the cell reference will change.
Putting a $ sign in front of the column letter makes it absolute. Meaning that when you drag the cell to the right, the column letter will not change.
Same goes for putting a $ sign in front of the row number.
You can toggle between the available cell references by hitting F4.

Hope that make sense.

To achieve what you want you don't have to think about absolute and relative cell references.
Just use this macro:

Sub test()
Dim x As Integer
x = InputBox("Which row to copy to?")
Range("I4").Copy Cells(x, 9)
Application.CutCopyMode = False
End Sub

Best regards,
Trowa
0
Thank you Trowa. This is working really well, but is there any way I can remove the requirement to type in the row number? The macro will always be run from the cell I need to paste to.
Thanks.
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 27, 2011 at 09:27 AM
Sure thing CS Macro,

The macro will then look like this:
Sub test()
Range("I4").Copy Destination:=ActiveCell
End Sub

Best regards,
Trowa
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 10, 2011 at 09:57 AM
I just learned that non-members can't see comments (thanks Aquarelle), so this message is a "reply", which you should be able to see.

Hi CS Macro,

Absolute and relative cell references.
When writing a function it is automatically a relative cell reference. Meaning that when you drag the cell, the cell reference will change.
Putting a $ sign in front of the column letter makes it absolute. Meaning that when you drag the cell to the right, the column letter will not change.
Same goes for putting a $ sign in front of the row number.
You can toggle between the available cell references by hitting F4.

Hope that make sense.

To achieve what you want you don't have to think about absolute and relative cell references.
Just use this macro:

Sub test() 
Dim x As Integer 
x = InputBox("Which row to copy to?") 
Range("I4").Copy Cells(x, 9) 
Application.CutCopyMode = False 
End Sub

Best regards,
Trowa
0