Select last sheet in wb when sheets are named

picklefactory

Well-known Member
Joined
Jan 28, 2005
Messages
506
Office Version
  1. 365
Platform
  1. Windows
Hi folks
Trying to find a way to simply select/activate the last sheet in a workbook (Last sheet extreme rh side of tabs, not last sheet used)
Sheets(Sheets.Count).Select doesn't seem to work, being as I am dynamically renaming each sheet as it is created, so I do not have Sheet1, Sheet2 etc.
Is there another way?
Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
No matter what the sheet names are, Sheets(Sheets.Count).Select should work. Have you tried to specify the workbook name also?
 
Upvote 0
No matter what the sheet names are, Sheets(Sheets.Count).Select should work. Have you tried to specify the workbook name also?
Nope, frayed knot. I get a run time error and it hangs on that line. I've also tried
VBA Code:
Workbooks("HOLIDAY BOOKING").Worksheets(Worksheets.Count).Select
But that also doesn't work
 
Upvote 0
What does the error state and the error number?
 
Upvote 0
.Worksheet() method only accepts sheet names afaik. wb.Sheets(Sheets.Count) must work because Sheets() method can work with numbers. Let say you have 5 sheets. Sheets.Count will return 5. wb.Sheets(Sheets.Count).Select must select 5th sheet. It has nothing to do with names or sheet order. Very strange indeed...
 
Upvote 0
What does the error state and the error number?
Hi Mark
On the Workbooks route I get 'Runtime error 9 Subscript out of range' and for the sheets method I get 'Runtime 1004 Select method of Worksheet class failed'
 
Upvote 0
How about
VBA Code:
With Workbooks("HOLIDAY BOOKING")
   .Activate
   .Worksheets(.Worksheets.Count).Select
End With
Thanks Fluff, but that also gives the Runtime 9 error. I'll post the full code in case there's something else I'm doing that affects it
 
Upvote 0
The full code is below, I'm using a UserForm as a password entry and depending on the password acceptance, there are further function.

VBA Code:
Private Sub CommandButton1_Click()
If TextBox1.Value = "Name" Then

Worksheets("Employee List").Range("J10").Value = "Name"

Worksheets("Input").Activate

ActiveWindow.DisplayWorkbookTabs = True

Unload Me

UserFormMain.Hide

With Workbooks("HOLIDAY BOOKING")
   .Activate
   .Worksheets(.Worksheets.Count).Select
End With

Else
MsgBox "WRONG PASSWORD.... BUGGER OFF!!", vbCritical + vbOKOnly, "Access denied"
Unload Me



End If

End Sub
 
Upvote 0
Try adding the file extension the workbook name.
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,715
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top