Macro to insert a blank column every second column plus highlight

B-radK

Board Regular
Joined
Apr 1, 2010
Messages
95
Office Version
  1. 365
Platform
  1. Windows
Hello team,

I need to insert a blank column every second column after column R, for approximately 100 columns. Once inserted, I need to colour the new blank columns in yellow.

Basically, I need to split the columns of data I have with a blank column in between, so I can do some calculations.

I can do this through recording a macro, but it is obviously messy, and I would like to tidy it up.

Sub Insert_Columns()

Range("R:R").Insert
Range("T:T").Insert
Range("V:V").Insert
Range("X:X").Insert
Range("Z:Z").Insert
etc. etc.

Could I have help on a macro to suit please? Any help would be much appreciated.

Thank you very much,
Brad.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this:
VBA Code:
Sub Insert_Columns()
'Modified 3/24/2020 7:28:09 AM EST
Application.ScreenUpdating = False
Dim i As Long
For i = 18 To 110 Step 2
Columns(i).Insert: Columns(i).Interior.Color = vbYellow
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Fantastic. Works a treat.

Thank you very much!!


(y)(y)
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
You said about 100 so I'm sure you can see how to modify script to your exact need.
Change 110 to your needs.
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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