Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Worksheet name as a string variable?

Status
Not open for further replies.

sjh

Programmer
Oct 29, 2001
263
US
Hi,
I tried the following code, but I get <Subscript out of range> error. Is this not possible? I want the sheetName to be dynamically changed depending on what user selected in the combo box cboReports.

Dim sheetName As String
sheetName = cboReports.Value & &quot; Reports&quot;
Sheets(sheetName).Select


Thank you!
 
Hi Skip,
I think you misunderstood my question.
I wanted my code to open up a worksheet whose name is selected in the combo box cboReports. I hope this makes sense. Thank you~

Private Sub buttonGoReports_Click()
Dim sheetName As String
sheetName = cboReports.Value & &quot; Reports&quot;
Sheets(sheetName).Select
End sub
 
I'm guessing that you're getting the <Subscript out of range> error because you don't have a worksheet with the name specified in the sheetName variable. You need to

a) check that the options available in the cboReports ComboBox match up with existing spreadsheets
b) check that the ComboBox doesn't allow new entries (.MatchRequired = True)

Hope this helps!
 
Hi there,

It's a silly question, but what is the naming convention for referring to worksheet reference name in VBA code?


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top