Macros finished now I need to add columns

kdunleav

New Member
Joined
Jul 27, 2011
Messages
2
I have completed worksheet that is all macro driven. I now need to add a couple of columns. The problem is when I add columns none of my macros adjust to the columns moving over. For example AA originally had a formula in it, now I added a column so AA is now AB. How can I have the Macros follow the column they were originally in? Any help would be great thank you.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I am new too excel VBA, so my advice probably won't be too helpful. I was hoping my question would spark the help of another more experienced user. From what I know about macro recorder when you look at the code using alt-F11 there will be a lot of ".selection" stuff in there. I'm not confident that this will have an affect on your code when items change in the sheet. you may want to go into the code and change some cell ranges so that they are hard-coded.

All the code I have programmed, the specific cells are hard-coded, and I can call those cells as if they were objects.

I may have time later to send a copy of a sample code of mine involving adding columns, currently I have to a meet a work deadline.

Good luck
 
Upvote 0
hi kdunleav
here is one option. There are other ways to add columns as well. I grabbed this one from a program I wrote a few days ago. You will notice that I am using array to achieve this. hope it helps :)

Code:
sub twoDimensionalArray()
dim classics (1 to 100, 1 to 100) as string
dim intRow as integer, intColumn as integer
dim numRow as integer, numColumn as integer

numRow=inputbox"input number of rows"
numColumn=inputbox"input number of columns"'these are so that the user 'can specify how many rows and columns they want. then the for...next 'loop will iterate the amount of times they desired
    for intRow=1 to numRow
    for intColumn=1 to numColumn
        classics(intRow,intColumn)=cells(intRow,intColumn).value
    next intColumn
    next intRow
end sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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