PC Review


Reply
Thread Tools Rate Thread

Deleting columns on multiple sheets

 
 
KHogwood-Thompson
Guest
Posts: n/a
 
      18th Aug 2008
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
 
Reply With Quote
 
 
 
 
Ardus Petus
Guest
Posts: n/a
 
      18th Aug 2008
Try this:

Dim ws as Worksheet

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

HTH
--
AP

"KHogwood-Thompson" <(E-Mail Removed)> a écrit
dans le message de news:
3084AD7E-BDFB-40FC-BA5B-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      18th Aug 2008
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" <(E-Mail Removed)> wrote in
message news:3084AD7E-BDFB-40FC-BA5B-(E-Mail Removed)...
> 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


 
Reply With Quote
 
KHogwood-Thompson
Guest
Posts: n/a
 
      18th Aug 2008
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" <(E-Mail Removed)> a écrit
> dans le message de news:
> 3084AD7E-BDFB-40FC-BA5B-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      18th Aug 2008
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
(E-Mail Removed)
"KHogwood-Thompson" <(E-Mail Removed)> wrote in
message news:3084AD7E-BDFB-40FC-BA5B-(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Columns in multiple Sheets Ken Microsoft Excel Misc 3 3rd Oct 2008 02:48 PM
Lookup across multiple columns within multiple sheets Garnet Microsoft Excel Misc 2 25th Jun 2008 11:46 PM
deleting columns on multiple sheets school counselor Microsoft Excel Misc 4 25th May 2008 10:22 PM
Multiple Sheets and Columns =?Utf-8?B?VG9tIEQ=?= Microsoft Excel Worksheet Functions 9 27th Apr 2007 06:42 PM
Deleting multiple sheets =?Utf-8?B?aHNoYXloMHJu?= Microsoft Excel Programming 12 11th Apr 2006 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:05 PM.