Find the last hidden sheet

B

bramnizzle

I have created a workbook that has multiple hidden and unhidden
sheets. I have a macro that allows the user to select hidden sheets
from a list. However, another option I need is for the user to be
able to select the very last sheet whether it is hidden or not.

Worksheets(Worksheets.Count).Activate
only works for sheets that are not hidden.

I want a macro that finds the very last sheet in the workbook, whether
it is hidden or not.

I thought of using the SelectSheets macro I have, but again, I don't
want to create a list of all sheets, I just want it to go directly to
*the very last sheet*.

Can anyone help?

Thanks in advance.
 
F

figueralex1

I have created a workbook that has multiple hidden and unhidden
sheets. I have a macro that allows the user to select hidden sheets
from a list. However, another option I need is for the user to be
able to select the very last sheet whether it is hidden or not.

Worksheets(Worksheets.Count).Activate
only works for sheets that are not hidden.

I want a macro that finds the very last sheet in the workbook, whether
it is hidden or not.

I thought of using the SelectSheets macro I have, but again, I don't
want to create a list of all sheets, I just want it to go directly to
*the very last sheet*.

Can anyone help?

Thanks in advance.
 
F

figueralex1

I have created a workbook that has multiple hidden and unhidden
sheets. I have a macro that allows the user to select hidden sheets
from a list. However, another option I need is for the user to be
able to select the very last sheet whether it is hidden or not.

Worksheets(Worksheets.Count).Activate
only works for sheets that are not hidden.

I want a macro that finds the very last sheet in the workbook, whether
it is hidden or not.

I thought of using the SelectSheets macro I have, but again, I don't
want to create a list of all sheets, I just want it to go directly to
*the very last sheet*.

Can anyone help?

Thanks in advance.
 
D

DomThePom

Have sa button then runs the following:

Sub activateLastSheet()
Dim s As Worksheet

Set s = ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
If s.Visible = xlSheetHidden Or s.Visible = xlSheetVeryHidden Then
s.Visible = xlSheetVisible
s.Activate
End If
set s = Nothing
End Sub
 
B

bramnizzle

Have sa button then runs the following:

Sub activateLastSheet()
Dim s As Worksheet

Set s = ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
If s.Visible = xlSheetHidden Or s.Visible = xlSheetVeryHidden Then
s.Visible = xlSheetVisible
s.Activate
End If
set s = Nothing
End Sub

SWEET!!! Works like a charm. Thanks much!!!
 

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

Top