Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Dunmarie
 
Posts: n/a
Default 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   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking sheets to a summary sheet in workbook gambinijr Excel Discussion (Misc queries) 4 December 16th 04 08:13 PM
linking multiple sheets to a summary sheet greg g Excel Discussion (Misc queries) 1 December 16th 04 07:43 AM
how can i select all the cells with same color on a sheet if there are multipale colors by vba code uobt Charts and Charting in Excel 1 December 15th 04 05:27 PM
Hyperlink to specific sheet in Excel Web File jd17 Links and Linking in Excel 0 December 8th 04 09:03 PM
Sheet tabs disappear sometimes in Internet Explorer Jan Nordgreen Excel Discussion (Misc queries) 0 December 6th 04 01:34 AM


All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"