Avoiding a hidden sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I currently have code to loop through the number of sheets in a workbook.....

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
For Each sh In mybook.Worksheets

......but I need to loop 1 less than the total number of sheets to avoid a
hidden sheet in the same workbook - in other words, I need something like.....
For Each [sh-1] In mybook.Worksheets..........

Any suggestions?

Thanks in advance.
 
Just avoid the hidden sheets.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
'do what you want
end if
next sh


I currently have code to loop through the number of sheets in a workbook.....

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
For Each sh In mybook.Worksheets

.....but I need to loop 1 less than the total number of sheets to avoid a
hidden sheet in the same workbook - in other words, I need something like.....
For Each [sh-1] In mybook.Worksheets..........

Any suggestions?

Thanks in advance.
 
Thanks Dave. When I saw your post, I thought "Duh" - I should've known that
- but I've been staring at this code for too long and don't know where I am
anymore.

I'll try it out. Again, thanks.

Dave Peterson said:
Just avoid the hidden sheets.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
'do what you want
end if
next sh


I currently have code to loop through the number of sheets in a workbook.....

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
For Each sh In mybook.Worksheets

.....but I need to loop 1 less than the total number of sheets to avoid a
hidden sheet in the same workbook - in other words, I need something like.....
For Each [sh-1] In mybook.Worksheets..........

Any suggestions?

Thanks in advance.
 
Sometimes, the extra set of eyes is enough to get you going again.
Thanks Dave. When I saw your post, I thought "Duh" - I should've known that
- but I've been staring at this code for too long and don't know where I am
anymore.

I'll try it out. Again, thanks.

Dave Peterson said:
Just avoid the hidden sheets.

For Each sh In mybook.Worksheets
if sh.visible = xlsheetvisible then
'do what you want
end if
next sh


I currently have code to loop through the number of sheets in a workbook.....

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
For Each sh In mybook.Worksheets

.....but I need to loop 1 less than the total number of sheets to avoid a
hidden sheet in the same workbook - in other words, I need something like.....
For Each [sh-1] In mybook.Worksheets..........

Any suggestions?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top