ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through sheets (https://www.excelbanter.com/excel-programming/386776-looping-through-sheets.html)

ReportSmith

Looping through sheets
 
I have code (Excel 2000) that loops through all the visible sheets in a
workbook. Problem is, when the code gets to the "next.sh" line, the next
worksheet is not selected.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then

JE McGimpsey

Looping through sheets
 
Why do you want to select the sheets? Using worksheet and range objects
directly is faster and easier to maintain.

However, if you really want to select, then

For Each sh in mybook.Worksheets
If sh.Visible = xlSheetVisible Then
sh.Select
'...
End If
Next sh


In article ,
ReportSmith wrote:

I have code (Excel 2000) that loops through all the visible sheets in a
workbook. Problem is, when the code gets to the "next.sh" line, the next
worksheet is not selected.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
.
...............
.
end if
next sh

Any ideas?

Thanks.


JLGWhiz

Looping through sheets
 
try this:

For Each sh In mybook.Worksheets
If sh.Visible = True Then

ReportSmith

Looping through sheets
 
I don't think my earlier reply was received...but in any case...I need to do
a lot of consolidating of non-standardized data on every sheet, so I have
nested loops and if..thens. I tried your suggestion and it worked.

Thank you.

"JE McGimpsey" wrote:

Why do you want to select the sheets? Using worksheet and range objects
directly is faster and easier to maintain.

However, if you really want to select, then

For Each sh in mybook.Worksheets
If sh.Visible = xlSheetVisible Then
sh.Select
'...
End If
Next sh


In article ,
ReportSmith wrote:

I have code (Excel 2000) that loops through all the visible sheets in a
workbook. Problem is, when the code gets to the "next.sh" line, the next
worksheet is not selected.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
.
...............
.
end if
next sh

Any ideas?

Thanks.



ReportSmith

Looping through sheets
 
Thanks for the suggestion. I tried what the earlier post recommended and it
worked. It's nice to know there are folks out there that are knowledgeable
and willing to assist.

Again, thanks.

"JLGWhiz" wrote:

try this:

For Each sh In mybook.Worksheets
If sh.Visible = True Then
.
...............
.
End If
Next sh


"ReportSmith" wrote:

I have code (Excel 2000) that loops through all the visible sheets in a
workbook. Problem is, when the code gets to the "next.sh" line, the next
worksheet is not selected.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
.
...............
.
end if
next sh

Any ideas?

Thanks.



All times are GMT +1. The time now is 11:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com