Deleting columns on multiple sheets

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??
 
A

Ardus Petus

Try this:

Dim ws as Worksheet

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

HTH
 
R

Rick Rothstein \(MVP - VB\)

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
 
D

Don Guillett

One way
Sub deletecolainallshts()
For i = 1 To Sheets.Count
Sheets(i).Columns("a").Delete
Next i
End Sub
 

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

Top