Selecting Next Worksheet

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

Guest

I would like to open a workbook and search the worksheets until the first
blank cell B25 is located and have the worksheet containing the blank cell
B25 be the active worksheet.
This is what I came up with and it is not working because I have a Next with
no For.

Private Sub Workbook_Open()
If B25 = "" Then
Next Worksheet.Select
End If

End Sub
Thanks for any help!
 
Private Sub Workbook_Open()
Dim sh as Worksheet
for each sh in Thisworkbook.Worksheets
If sh.Range("B25").Value = "" Then
sh.Select
sh.Range("B25").Select
exit for
End If
Next
End Sub
 
Thanks so much Tom, it works perfectly.
Just as an FYI, if any of the sheets in the workbook are hidden and have
empty cells in the range value the VB will post an error. It wasn't a big
deal for me as I just use the hidden sheets as range separators.
Thanks again!
 
Private Sub Workbook_Open()
Dim sh as Worksheet
for each sh in Thisworkbook.Worksheets
if sh.Visible = xlSheetVisible then
If sh.Range("B25").Value = "" Then
sh.Select
sh.Range("B25").Select
exit for
End If
end if
Next
End Sub
 

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