Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 279
Default Looping Problem . . .Argh!

I am using the following code to cycle through open sheets and hide those
with nothing in Cell A2. When I run the code, it never changes sheets, it
just applies the logic to the same sheet.

Dim SH As Worksheet
Dim xlRng As Object 'Excel.Range
Dim xlApp As Excel.Application

For Each SH In xlApp.ActiveWorkbook.Worksheets
Set xlRng = xlApp.Range("A2")
If xlRng = "" Then xlApp.ActiveWindow.SelectedSheets.Visible = False
Next SH

Any Ideas
  #3   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Looping Problem . . .Argh!

I tried your code but it still will not move on to the next "For" command. It
still tries to apply the changes to the one sheet.

"Don Guillett" wrote:

try this
Sub hideshts()
For Each ws In Worksheets
If ws.Range("a2") = "" Then ws.Visible = False
Next
End Sub

--
Don Guillett
SalesAid Software

"ed" wrote in message
...
I am using the following code to cycle through open sheets and hide those
with nothing in Cell A2. When I run the code, it never changes sheets, it
just applies the logic to the same sheet.

Dim SH As Worksheet
Dim xlRng As Object 'Excel.Range
Dim xlApp As Excel.Application

For Each SH In xlApp.ActiveWorkbook.Worksheets
Set xlRng = xlApp.Range("A2")
If xlRng = "" Then xlApp.ActiveWindow.SelectedSheets.Visible = False
Next SH

Any Ideas




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Looping Problem . . .Argh!

My code, which is similar to Don's works fine unless you are trying to hide
the only visible sheet in the workbook (you cannot hide all sheets in a
workbook).

Sub HideSheets()

For Each ws In Worksheets
If ws.Range("A2") = "" Then
ws.Visible = False
End If
Next ws

End Sub

"e" wrote in message
...
I tried your code but it still will not move on to the next "For" command.

It
still tries to apply the changes to the one sheet.

"Don Guillett" wrote:

try this
Sub hideshts()
For Each ws In Worksheets
If ws.Range("a2") = "" Then ws.Visible = False
Next
End Sub

--
Don Guillett
SalesAid Software

"ed" wrote in message
...
I am using the following code to cycle through open sheets and hide

those
with nothing in Cell A2. When I run the code, it never changes sheets,

it
just applies the logic to the same sheet.

Dim SH As Worksheet
Dim xlRng As Object 'Excel.Range
Dim xlApp As Excel.Application

For Each SH In xlApp.ActiveWorkbook.Worksheets
Set xlRng = xlApp.Range("A2")
If xlRng = "" Then xlApp.ActiveWindow.SelectedSheets.Visible =

False
Next SH

Any Ideas






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
Scrolling Looping Problem Nick Wakeham Excel Discussion (Misc queries) 0 June 12th 07 01:42 PM
If Then Else looping problem Kieran1028[_12_] Excel Programming 1 November 11th 04 06:27 PM
Argh...layering object problem in userform jasonsweeney[_70_] Excel Programming 2 April 21st 04 07:22 PM
complex looping problem Max Bialystock Excel Programming 16 April 10th 04 01:56 PM
Looping Problem Todd Huttenstine[_3_] Excel Programming 5 January 25th 04 12:51 AM


All times are GMT +1. The time now is 06:59 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"