Select sheet with VB code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Excel Workbook with a couple of sheets. I would like to call a sheet
depending on a variable selected by the user.
My current code is as follows:
Dim xlw As Excel.Workbook
Dim xls As Excel.Worksheet
Dim xla As Excel.Application

Set xlw = GetObject("G:\Stock Take\Stock Month-End.xls")
Set xls = xlw.ActiveSheet
Set xla = xlw.Parent

[Text44] = xls.Cells(10, 2)
[Text54] = xls.Cells(10, 3)
[Text63] = xls.Cells(10, 4)
[Text201] = xls.Cells(10, 5)
[Text212] = xls.Cells(10, 7)
[Text90] = xls.Cells(10, 8)

The variable is created by then user making a selection from a combo box.
Example:
User select "January" which creates a variable called "varMonth" containing
"Jan" which I would like to use to call a sheet called "Jan" inside the
workbook.
I can create the variable, I would just like to know how to use the variable
to select the sheet.
Any help will be appreciated.
Thanks.
 
Dunmarie,

Assuming everything else in your code works, something along the lines of:

xlw.Worksheets(varMonth).Select

HTH,
Bernie
MS Excel MVP
 

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

Back
Top