Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / August 2008

Tip: Looking for answers? Try searching our database.

Deleting columns on multiple sheets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KHogwood-Thompson - 18 Aug 2008 09:35 GMT
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??
Signature

K Hogwood-Thompson

Ardus Petus - 18 Aug 2008 09:42 GMT
Try this:

Dim ws as Worksheet

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

HTH
--
AP

"KHogwood-Thompson" <KHogwoodThompson@discussions.microsoft.com> a écrit
dans le message de news:
3084AD7E-BDFB-40FC-BA5B-904F9431F140@microsoft.com...
> Hi,
>
[quoted text clipped - 8 lines]
>
> Can anyone help to modify the code??
KHogwood-Thompson - 18 Aug 2008 09:53 GMT
Yes that works perfectly. Many thanks Ardus!
Signature

K Hogwood-Thompson

> Try this:
>
[quoted text clipped - 23 lines]
> >
> > Can anyone help to modify the code??
Rick Rothstein (MVP - VB) - 18 Aug 2008 09:49 GMT
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

> Hi,
>
[quoted text clipped - 8 lines]
>
> Can anyone help to modify the code??
Don Guillett - 18 Aug 2008 13:28 GMT
One way
Sub deletecolainallshts()
For i = 1 To Sheets.Count
 Sheets(i).Columns("a").Delete
Next i
End Sub

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

> Hi,
>
[quoted text clipped - 8 lines]
>
> Can anyone help to modify the code??
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.