Paste values into next column - Excel 2010

Cadenzza

New Member
Joined
Jul 15, 2014
Messages
1
Hello,

this is my first post here so be gentle :)

I need to paste cell values from one column to another via button.

Code I use is this:
Code:
Sub Macro1()Dim myRange As Range
    Range("AH5:AH32").Select
    Selection.Copy
    Range("D5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Set myRange = Selection
    myRange.Offset(0, 1).Select
End Sub

What I want is a way to make selected column "stuck" in macro. So, If I use this code above selection is moved from D5 to E5. I want to have that E5 setting saved so next time I use that macro it will start from E5 and move to F5. That setting should be saved even after I save workbook and close it completely.

Is that even possible and if yes, how?

I am learning VBA so be easy on me.

Regards,
Mario (Cadenzza)
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hello Mario
The only way that I know of will be to write the cell reference to the sheet.
I have used cell A1, but you can change that to any spare cell. So if you put D5 into cell A1 & run the following code, your range will be copied into D5 & A1 will change to $E$5.
Hope this makes sense

Code:
Sub Macro1()

    Dim RngStr As String
    
    RngStr = Range("A1").Value
    Range("AH5:AH32").Copy Destination:=Range(RngStr)
    Range("A1").Value = Range(RngStr).Offset(, 1).Address

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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