Just imagine if you could.....

Climber

New Member
Joined
Jun 14, 2006
Messages
19
.....allow many months to go by between each occasion you use VBA.

You'd get so rusty that you'd forget how to do the simplest things.

I've a simple textbox collects a variable between 1-18. All I want to do is use that variable to point to a workbook sheet bearing a generic text name before that number.

So in other words, my code would look something like this ??????

Or am I way off ....?????

Private Sub CommandButton1_Click()
Dim myvar As Integer
myvar = TextBox1.Value
Sheets("name" + myvar).Select
UserForm1.Hide

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Untested, but I would use your code, adapted like so:

Private Sub CommandButton1_Click()
Dim myvar As string
myvar = TextBox1.Text
Sheets("name" & myvar).Select
UserForm1.Hide

End Sub

Hope this helps, Patrick.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, climber,

the only real mistake is your "plus"sign
Sheets("name" + myvar).Select
you can not "addup" strings

you need the "&" sign
Sheets("name" & myvar).Select

remark: in most of the case, you don't need to select anything within your code

example
Code:
Sheets(1).Range("A1") = 1

kind regards,
Erik
 

Watch MrExcel Video

Forum statistics

Threads
1,133,460
Messages
5,658,899
Members
418,475
Latest member
ExcelBeginner233

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top