ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Changing Column Reference in Macros? (https://www.excelbanter.com/excel-discussion-misc-queries/246827-changing-column-reference-macros.html)

JDM

Changing Column Reference in Macros?
 
I want to write a macro that will move to the next column each time I run it.
Below is what I have from a recording. I need to change the "AC:AC" to
"AD:AD" next time I run this macro, same for the AD below that. I can create
a table in my worksheets that will always have the new column to point to,
but I don't know how to reference it in my macro.

ActiveWindow.SmallScroll Down:=-16
Sheets(Array("Deposits", "Rates")).Select
Sheets("Deposits").Activate
Columns("AC:AC").Select
Application.CutCopyMode = False
Selection.Copy
Columns("AD:AD").Select
Selection.Insert Shift:=xlToRight
Columns("AC:AC").Select

FSt1

Changing Column Reference in Macros?
 
hi
you could use a variable in a cell on the sheet. just type in the next
column. then add this to your code.

dim v as string
v = range("A1").value
colunms(v).select

regards
FSt1



"JDM" wrote:

I want to write a macro that will move to the next column each time I run it.
Below is what I have from a recording. I need to change the "AC:AC" to
"AD:AD" next time I run this macro, same for the AD below that. I can create
a table in my worksheets that will always have the new column to point to,
but I don't know how to reference it in my macro.

ActiveWindow.SmallScroll Down:=-16
Sheets(Array("Deposits", "Rates")).Select
Sheets("Deposits").Activate
Columns("AC:AC").Select
Application.CutCopyMode = False
Selection.Copy
Columns("AD:AD").Select
Selection.Insert Shift:=xlToRight
Columns("AC:AC").Select


FSt1

Changing Column Reference in Macros?
 
hi again
forgot to mention. you don't need to reverence the column as AC:AC. you can
use just AC. excel will understand.

regards
FSt1

"JDM" wrote:

I want to write a macro that will move to the next column each time I run it.
Below is what I have from a recording. I need to change the "AC:AC" to
"AD:AD" next time I run this macro, same for the AD below that. I can create
a table in my worksheets that will always have the new column to point to,
but I don't know how to reference it in my macro.

ActiveWindow.SmallScroll Down:=-16
Sheets(Array("Deposits", "Rates")).Select
Sheets("Deposits").Activate
Columns("AC:AC").Select
Application.CutCopyMode = False
Selection.Copy
Columns("AD:AD").Select
Selection.Insert Shift:=xlToRight
Columns("AC:AC").Select



All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com