How to insert columns aftre each column of data

V

vcff

Hi All

I need to insert blank columns after each column of data on several
worksheets.
Can help?

Thanks in advance.

vcff
 
D

Dave Peterson

Group the worksheets that should have this done to them.
Click on the first tab and ctrl-click on subsequent.

Then run a macro:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim iCol As Long
For Each wks In ActiveWindow.SelectedSheets
With wks
For iCol _
= .Cells.SpecialCells(xlCellTypeLastCell).Column To 1 Step -1
.Columns(iCol).Insert
Next iCol
End With
Next wks
End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)
 
D

Dave Peterson

ps. remember to ungroup the sheets when you're done.

Rightclick on one of the selected sheets and choose Ungroup Sheets.
 
G

Gary''s Student

Try this simple macro:

Sub column_adder()
Application.ScreenUpdating = False
Dim r As Range
For i = Columns.Count To 2 Step -1
Set r = Columns(i)
r.Select
If Application.WorksheetFunction.CountA(r) > 0 Then
Selection.Insert Shift:=xlToRight
End If
Next
Application.ScreenUpdating = True
End Sub
 
M

Mike H.

This macro would work.

Sub InsertCols()
'assume that a column has data if there is something in row 1
Range("IV1").End(xlToLeft).Select
Let Y = ActiveCell.Column 'there are Y # of columns to insert
For X = 1 To Y
Columns(X + X).Select
Selection.Insert Shift:=xlToRight
Next

End Sub
 
V

vcff

Hi Dave,

Thanks for the reminder.

vcff

Dave Peterson said:
ps. remember to ungroup the sheets when you're done.

Rightclick on one of the selected sheets and choose Ungroup Sheets.
 
Top