Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Select sheet with VB code
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. |
#2
|
|||
|
|||
Dunmarie,
Assuming everything else in your code works, something along the lines of: xlw.Worksheets(varMonth).Select HTH, Bernie MS Excel MVP "Dunmarie" wrote in message ... 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Linking sheets to a summary sheet in workbook | Excel Discussion (Misc queries) | |||
linking multiple sheets to a summary sheet | Excel Discussion (Misc queries) | |||
how can i select all the cells with same color on a sheet if there are multipale colors by vba code | Charts and Charting in Excel | |||
Hyperlink to specific sheet in Excel Web File | Links and Linking in Excel | |||
Sheet tabs disappear sometimes in Internet Explorer | Excel Discussion (Misc queries) |