Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping Problem . . .Argh!
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping Problem . . .Argh!
I found the problem. For some reason If I used the IF/Then on the same line
without an End if it screwed up. Once I went with the longer form, all worked. Thanks for your help. "Don Guillett" wrote: The code DOES work and doesn't need to change sheet to do so. -- Don Guillett SalesAid Software "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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Looping Problem . . .Argh!
shouldn't. You can use if dddd then eeeeee without endif on SAME line or
even with a _ continuation char. Else use if ddd then eee end if -- Don Guillett SalesAid Software "as" wrote in message ... I found the problem. For some reason If I used the IF/Then on the same line without an End if it screwed up. Once I went with the longer form, all worked. Thanks for your help. "Don Guillett" wrote: The code DOES work and doesn't need to change sheet to do so. -- Don Guillett SalesAid Software "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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Scrolling Looping Problem | Excel Discussion (Misc queries) | |||
If Then Else looping problem | Excel Programming | |||
Argh...layering object problem in userform | Excel Programming | |||
complex looping problem | Excel Programming | |||
Looping Problem | Excel Programming |