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 total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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
Back
Top