Unable to Open My Workbook at a Specific Tab

DavidWF

Board Regular
Joined
Oct 14, 2015
Messages
130
I'd appreciate guidance with the following.

I'm trying to open a workbook at a specific tab, using:

Code:
Private Sub Workbook_Open()

Sheets(“Sheet26”).Select

Range(“B2”).Select

End Sub

in ThisWorkbook, however every time I open the workbook it opens at the last used tab and displays an error pop-up - Run-time error '9': Subscript out of range

Running Debug highlights the
Code:
Sheets("Sheet26").Select
line. I've tried replacing "Sheet26" with the actual tab name but I get the same result.

What have I done wrong and what should I have done?
 
Thanks Mark

Code:
Application.Goto Sheet26.Range("B2"), True

solved the problem. The workbook now opens correctly.

No idea what the issue with the quote marks might be - maybe because we're upside down on this side of the planet.

Happy got there but with the quotes I'd think either you copied the code from somewhere or someone has played with the font in the VB Editor.
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Oops - the dangers of multi-tasking!!

Mark - you are absolutely spot-on. I'm in the midst of trying to do three things at once and have spent the past 2 - 3 hrs switching back and forth between them. Sort of from laziness, I copied the original code from another forum and quickly modified it to suit my specifics; I omitted to replace the quote marks. Even with the multiple comments about the quotes, it still didn't gel that I'd used text from another source. " . . . copied the code . . " was what finally woke me up. FYI, after re-typing the original code it all worked fine.

Lesson learned!!!

Although - the good part is that I've learned another way to code the requirement.

Thanks again.
 
Upvote 0
You're welcome and thanks for the feedback.
 
Upvote 0
No idea what the issue with the quote marks might be - maybe because we're upside down on this side of the planet.

FWIW, Copying code from a word processor or web page can get you into trouble sometimes with quotes. A word processing program like MS Word uses typographic double quotes (“Hello”), also known as curly or 'smart' quotes. With these, the open double quote and closed double quote are different characters. With VBA, you must always use straight ascii double quotes ("Hello").
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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