Automating inserting columns

Matthayter

New Member
Joined
Apr 21, 2015
Messages
8
Afternoon all;

Hoping someone can help me with what im sure is a simple problem.

I have an excel SS that has roughly 100 columns populated with data. However I need to insert a column starting with column D and then automatically inserting a new column every other column after that. E.g insert a column in D, F, H, J and so on and so on

any help greatly appreciated as the though of doing it manually is mundane

Thanks
Matt
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Re: Automatting inserting columna

I'm still learning, so I can't promise I can help you, but I need to understand if I am even to try.

Is there always data in row 1 (ie. if the macro sees a value in row 1 of a column after D, then insert a new column)?
If not, does the number of columns of data always stay the same? how many, and what columns contain data?
How often would you want this to happen? only once? every time a button is clicked? every time spreadsheet is opened? etc...

I'll do my best to help, but I don't want to spend my time on it if I misunderstand the end goal/requirements.
 
Upvote 0
Re: Automatting inserting columna

Try this:
Code:
Sub MyInsertMacro()

    Dim c As Long
    
    Application.ScreenUpdating = False
    
    For c = 4 To 100 Step 2
        Columns(c).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Next c
    
    Application.ScreenUpdating = True
    
End Sub
You will just need to updated "100" to reflect how far our you want to go.
 
Upvote 0
Re: Automatting inserting columna

Try this:
Code:
Sub MyInsertMacro()

    Dim c As Long
    
    Application.ScreenUpdating = False
    
    For c = 4 To 100 Step 2
        Columns(c).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Next c
    
    Application.ScreenUpdating = True
    
End Sub
You will just need to updated "100" to reflect how far our you want to go.


Thank you that worked perfectly

Matthew
 
Upvote 0
Re: Automatting inserting columna

You are welcome.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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