Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert Columns on Every Sheet
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert Columns on Every Sheet
Sub INSERT_COLUMNS()
Dim w As Worksheet For Each w In ActiveWorkbook.Worksheets w.Columns("A:B").Insert Next w End Sub -- Regards, Tom Ogilvy "Sige" wrote in message ups.com... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert Columns on Every Sheet
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 "Sige" wrote: 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert Columns on Every Sheet
Make "Columns("A:B").Insert" read "w.Columns("A:B").Insert -- kralj ----------------------------------------------------------------------- kraljb's Profile: http://www.excelforum.com/member.php...nfo&userid=995 View this thread: http://www.excelforum.com/showthread.php?threadid=39060 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert Columns on Every Sheet
Thx all! Time for coffee or more sleep. "NOSPAM" to be removed for direct mailing... *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reference changes when I insert new columns in the source sheet | Excel Discussion (Misc queries) | |||
2007 excel work sheet will not allow to insert rows or columns | Excel Discussion (Misc queries) | |||
can't insert a column, can't shift columns off the sheet. | Excel Discussion (Misc queries) | |||
How to Insert Columns in a big Sheet... | Excel Worksheet Functions | |||
unable to insert columns in excel, insert- columns (disabled) | Excel Discussion (Misc queries) |