![]() |
Deleting columns on multiple sheets
Hi,
I have a macro that attempts to delete column A on all sheets in the workbook. What it currently does s delete all columns on the first sheet (activesheet) only. For Each ws In ActiveWorkbook.Worksheets Columns("A:A").Select Selection.Delete Shift:=xlToLeft Next Can anyone help to modify the code?? -- K Hogwood-Thompson |
Deleting columns on multiple sheets
Try this:
Dim ws as Worksheet For Each ws In ActiveWorkbook.Worksheets ws.Columns("A").Delete Shift:=xlToLeft Next HTH -- AP "KHogwood-Thompson" a écrit dans le message de news: ... Hi, I have a macro that attempts to delete column A on all sheets in the workbook. What it currently does s delete all columns on the first sheet (activesheet) only. For Each ws In ActiveWorkbook.Worksheets Columns("A:A").Select Selection.Delete Shift:=xlToLeft Next Can anyone help to modify the code?? -- K Hogwood-Thompson |
Deleting columns on multiple sheets
You are iterating the worksheets but not giving your commands a reference to
it (hence, you keep deleting Column A on the active sheet, once per sheet in the workbook). Also, whenever you see the selection of some range followed by a method of that selection, you can almost always combine it into one statement. Try this... For Each ws In ActiveWorkbook.Worksheets ws.Columns("A:A").Delete Shift:=xlToLeft Next Rick "KHogwood-Thompson" wrote in message ... Hi, I have a macro that attempts to delete column A on all sheets in the workbook. What it currently does s delete all columns on the first sheet (activesheet) only. For Each ws In ActiveWorkbook.Worksheets Columns("A:A").Select Selection.Delete Shift:=xlToLeft Next Can anyone help to modify the code?? -- K Hogwood-Thompson |
Deleting columns on multiple sheets
Yes that works perfectly. Many thanks Ardus!
-- K Hogwood-Thompson "Ardus Petus" wrote: Try this: Dim ws as Worksheet For Each ws In ActiveWorkbook.Worksheets ws.Columns("A").Delete Shift:=xlToLeft Next HTH -- AP "KHogwood-Thompson" a écrit dans le message de news: ... Hi, I have a macro that attempts to delete column A on all sheets in the workbook. What it currently does s delete all columns on the first sheet (activesheet) only. For Each ws In ActiveWorkbook.Worksheets Columns("A:A").Select Selection.Delete Shift:=xlToLeft Next Can anyone help to modify the code?? -- K Hogwood-Thompson |
Deleting columns on multiple sheets
One way
Sub deletecolainallshts() For i = 1 To Sheets.Count Sheets(i).Columns("a").Delete Next i End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "KHogwood-Thompson" wrote in message ... Hi, I have a macro that attempts to delete column A on all sheets in the workbook. What it currently does s delete all columns on the first sheet (activesheet) only. For Each ws In ActiveWorkbook.Worksheets Columns("A:A").Select Selection.Delete Shift:=xlToLeft Next Can anyone help to modify the code?? -- K Hogwood-Thompson |
All times are GMT +1. The time now is 05:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com