ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting Next Worksheet (https://www.excelbanter.com/excel-programming/360326-selecting-next-worksheet.html)

Fleone

Selecting Next Worksheet
 
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!

Tom Ogilvy

Selecting Next Worksheet
 
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

--
Regards,
Tom Ogilvy


"Fleone" wrote:

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!


Fleone

Selecting Next Worksheet
 
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!

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Fleone" wrote:

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!


Tom Ogilvy

Selecting Next Worksheet
 
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

--
Regards,
Tom Ogilvy


"Fleone" wrote:

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!

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Fleone" wrote:

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!



All times are GMT +1. The time now is 09:44 AM.

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