Macro to insert and move columns

A

andrea

Hi
Hopefully you can help please...

I need to compare Budget v Actuals. Currently the spreadsheet appears
similar to below:
Budget Actual
Region A Region B Region C Region A Region B Region C
ie Regions are grouped under Budget and Actual
What I require is...
Region A Bud Region A Act Variance Region B Bud Region B Act
Varianc etc

I have recorded a very basic macro that cuts and inserts columns. It does
not have the variance column included at the moment. There has to be a
better way!!

Columns("C:L").Select
Range("C2").Activate
Selection.Insert Shift:=xlToRight
Columns("M:M").Select
Range("M2").Activate
Selection.Cut
Columns("C:C").Select
Range("C2").Activate
Selection.Insert Shift:=xlToRight
Columns("AH:AH").Select
Range("AH2").Activate
Selection.Cut
Columns("D:D").Select
Range("D2").Activate
Selection.Insert Shift:=xlToRight


Thanks in advance
Andrea
 
J

Joel

I simplified the macro. I comment out the old code and show the new code
below the comments

'Columns("C:L").Select
'Range("C2").Activate
'Selection.Insert Shift:=xlToRight
Columns("C").Insert

'Columns("M:M").Select
'Range("M2").Activate
'Selection.Cut
Columns("M:M").Cut

'Columns("C:C").Select
'Range("C2").Activate
'Selection.Insert Shift:=xlToRight
Columns("C:C").insert Shift:=xlToRight

'Columns("AH:AH").Select
'Range("AH2").Activate
'Selection.Cut
Columns("AH:AH").Cut

'Columns("D:D").Select
'Range("D2").Activate
'Selection.Insert Shift:=xlToRight
Columns("D:D").insert Shift:=xlToRight
 
A

andrea

Thanks Joel, but there must be an easier way.

At times the columns can represent up to 20 regions, so this process would
have to be done 40 times and that doesn't take into account adding the
variance column which is not included in the recorded macro at the moment.

Andrea
 
J

Joel

I put the following dat in the worksheet
G1 = 1
J1 = 2
M1 = 3
P1 = 4

Then ran code below


For i = Columns("P").Column To Columns("G").Column Step -2
Columns(i).Cut
Columns("C").Insert Shift:=xlToRight
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top