Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro Help - Looping & Deleting

Hi, could someone please help me with this macro? It only works on the
active sheet when the "if" condition is met; otherwise it deletes all
the columns to the right of column R. It does nothing to the other
sheets. Sorry, I'll get better at this eventually.

Thanks!

-----

Sub DeleteColumnsAll()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

If InStr(Range("R2").Text, "Apple") Then
Columns("AC:AW").Delete
Else: Columns("S:AB").Delete
End If

Next ws

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Macro Help - Looping & Deleting

On Aug 12, 7:22*pm, Excel Hates Me wrote:
Hi, could someone please help me with this macro? It only works on the
active sheet when the "if" condition is met; otherwise it deletes all
the columns to the right of column R. It does nothing to the other
sheets. Sorry, I'll get better at this eventually.

Thanks!

-----

Sub DeleteColumnsAll()

* * *Dim ws As Worksheet

* * *For Each ws In ActiveWorkbook.Worksheets

* * * * * * If InStr(Range("R2").Text, "Apple") Then
* * * * * * Columns("AC:AW").Delete
* * * * * * Else: Columns("S:AB").Delete
* * * * * * End If

* * *Next ws

End Sub


Actually, Excel loves you (it just has difficulty expressing that
love)
You need to qualify your references:

Sub ExcelLovesYou()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws
If InStr(.Range("R2").Text, "Apple") Then
.Columns("AC:AW").Delete
Else
.Columns("S:AB").Delete
End If
End With
Next ws
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro Help - Looping & Deleting

Thank you James!

It does seem quite possible that I wouldn't understand Excel's
expressions anyway :)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Macro Lori from Minnesota Excel Programming 3 March 19th 09 07:04 PM
Looping macro Aaron Howe[_2_] Excel Programming 7 October 11th 07 12:06 PM
Looping and deleting thru cells which values offset LuisE Excel Programming 1 September 7th 07 05:32 AM
Deleting named ranges by looping through range collection agarwaldvk[_11_] Excel Programming 3 August 3rd 04 01:00 AM
looping through range and deleting cell contents. Andy Healey Excel Programming 1 December 31st 03 09:48 PM


All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"