Insert Columns on Every Sheet

S

Sige

Hi All,

If I want to insert a new column A&B on every sheet in the workbook I
thought to run this sub:

Sub INSERT_COLUMNS()
Dim w As Worksheet
For Each w In ActiveWorkbook.Worksheets
Columns("A:B").Insert
Next w
End Sub

What it does:
On the active sheet it inserts 2 columns times the number of sheets in
the workbook.
So, if you have 5 worksheets...it inserts 10 columns on the active
sheet!

I am ashamed ...
What is wrong with the code ... / me?

Sige
 
T

Tom Ogilvy

Sub INSERT_COLUMNS()
Dim w As Worksheet
For Each w In ActiveWorkbook.Worksheets
w.Columns("A:B").Insert
Next w
End Sub
 
G

Guest

The problem is that you haven't qualified the columns

Instead of
Columns("A:B").Insert

You shoud have said w.Columns("A:B").Insert

This will insert two columns on each sheet. If yuou want to install one
column between A and B then you need
w.Columns("A").Insert
 

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

Similar Threads


Top