Deleting columns on multiple sheets

  • Thread starter Thread starter KHogwood-Thompson
  • Start date Start date
K

KHogwood-Thompson

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??
 
Try this:

Dim ws as Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Columns("A").Delete Shift:=xlToLeft
Next

HTH
 
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
 
One way
Sub deletecolainallshts()
For i = 1 To Sheets.Count
Sheets(i).Columns("a").Delete
Next i
End Sub
 
Back
Top