Select Worksheet and then Reference

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

I have a button that i want to add code to. When this button is clicked, a box will appear that lets the user select the worksheet they want to use. I then need to put language in similiar to ws='user slectected worksheet' so that i can import data from that worksheet.

Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Place this code attached to your button

Code:
Dim sName As String
sName = InputBox("What Sheet to open?")
Sheets(sName).Select
 
Upvote 0
OK, this works. I just don't know how to save the selected workbook name in my code. So that ws="selected workbook"

Dim book As Workbook, sheet As Worksheet
For Each book In Workbooks
UserForm1.ComboBox1.AddItem book.Name
Next book
UserForm1.Show
 
Upvote 0
Maybe something like
Code:
Set Ws = Workbooks(ComboBox1.Value).Sheets("Sheet1")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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