Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MAS MAS is offline
external usenet poster
 
Posts: 18
Default Assign variable to a worksheet ?

Hi all,

How do I assign a variable to a worksheet ?

I have a form into which I want to enter a number such as 2467 and when I
click on a command button in that form I want the number "2467" to become
the variable "myclasssheet" to work with the following command.

Workbooks("Toolbox.xls").Worksheets("myclasssheet" ).Activate

Any help please.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Assign variable to a worksheet ?

You can always assign the Sheet a Name and then use a string variable:


Dim myclasssheet as String
Sheets("Sheet1").Name = "MAS"
myclasssheet = Sheets("Sheet1").Name

and then

Workbooks("Toolbox.xls").Worksheets(myclasssheet). Activate
instead of
Workbooks("Toolbox.xls").Worksheets("MAS").Activat e
--
Gary''s Student


"MAS" wrote:

Hi all,

How do I assign a variable to a worksheet ?

I have a form into which I want to enter a number such as 2467 and when I
click on a command button in that form I want the number "2467" to become
the variable "myclasssheet" to work with the following command.

Workbooks("Toolbox.xls").Worksheets("myclasssheet" ).Activate

Any help please.



  #3   Report Post  
Posted to microsoft.public.excel.programming
MAS MAS is offline
external usenet poster
 
Posts: 18
Default Assign variable to a worksheet ?

Thanks Gary but I am not explaining myself very well sorry.

I have a workbook with 20 worksheets numbered say 1101 to 1120 and I want to
be able to just enter the worksheet number into a textbox in a form and
display that one sheet when i click on the command button in the form.

I.e. Enter 1115 in the form, click on the command button and sheet 1115 is
displayed on screen.

All the other sheets will be hidden you see.

Mark

"Gary''s Student" wrote in message
...
You can always assign the Sheet a Name and then use a string variable:


Dim myclasssheet as String
Sheets("Sheet1").Name = "MAS"
myclasssheet = Sheets("Sheet1").Name

and then

Workbooks("Toolbox.xls").Worksheets(myclasssheet). Activate
instead of
Workbooks("Toolbox.xls").Worksheets("MAS").Activat e
--
Gary''s Student


"MAS" wrote:

Hi all,

How do I assign a variable to a worksheet ?

I have a form into which I want to enter a number such as 2467 and when I
click on a command button in that form I want the number "2467" to become
the variable "myclasssheet" to work with the following command.

Workbooks("Toolbox.xls").Worksheets("myclasssheet" ).Activate

Any help please.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Assign variable to a worksheet ?

Well O.K.


Sub gsnu()
Dim ws As Worksheet
s = InputBox("enter sheet number:")
s = "Sheet" & s
For Each ws In Worksheets
If ws.Name = s Then
ws.Activate
Exit Sub
End If
Next
MsgBox ("can't find " & s)
End Sub

The user is asked to supply a number. Say 1234. If Sheet1234 exists, it
will be activated. If Sheet1234 does not exist, an error message is output.
--
Gary's Student


"MAS" wrote:

Thanks Gary but I am not explaining myself very well sorry.

I have a workbook with 20 worksheets numbered say 1101 to 1120 and I want to
be able to just enter the worksheet number into a textbox in a form and
display that one sheet when i click on the command button in the form.

I.e. Enter 1115 in the form, click on the command button and sheet 1115 is
displayed on screen.

All the other sheets will be hidden you see.

Mark

"Gary''s Student" wrote in message
...
You can always assign the Sheet a Name and then use a string variable:


Dim myclasssheet as String
Sheets("Sheet1").Name = "MAS"
myclasssheet = Sheets("Sheet1").Name

and then

Workbooks("Toolbox.xls").Worksheets(myclasssheet). Activate
instead of
Workbooks("Toolbox.xls").Worksheets("MAS").Activat e
--
Gary''s Student


"MAS" wrote:

Hi all,

How do I assign a variable to a worksheet ?

I have a form into which I want to enter a number such as 2467 and when I
click on a command button in that form I want the number "2467" to become
the variable "myclasssheet" to work with the following command.

Workbooks("Toolbox.xls").Worksheets("myclasssheet" ).Activate

Any help please.






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
Assign value to a variable name Gnarlodious Excel Discussion (Misc queries) 2 August 20th 06 07:10 AM
Assign value to variable rroach Excel Discussion (Misc queries) 1 July 13th 05 05:24 AM
Assign a worksheet name to a variable benjammind[_4_] Excel Programming 3 July 11th 05 11:16 AM
Add new worksheet and assign it to an object variable? Thief_ Excel Programming 2 April 4th 05 07:21 AM
assign variable Tim Excel Programming 10 October 1st 04 07:33 PM


All times are GMT +1. The time now is 02:13 PM.

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

About Us

"It's about Microsoft Excel"