![]() |
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 |
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 |
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 |
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 |
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 *** |
All times are GMT +1. The time now is 02:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com