Select TAB Macro

cfer

Well-known Member
Joined
Jul 29, 2002
Messages
560
Hi,

I have the following in a Macro, works fine, now I want to improve it a bit.

ThisWorkbook.Sheets("Details").Range("Q7").Value = Sheets("Data").Range("M27").Value

I have a user form that will give an option to select,several TAB names.

When selected, the name is entered into Sheet1 cell A1.

What code would I need, to have the line in "ThisWorkbook.Sheets("Details")" "Details" be whatever is selected from A1.

IE, If Cell A1 had "Misc", then the Misc would be selected

ThisWorkbook.Sheets("Misc").Range("Q7").Value = Sheets("Data").Range("M27").Value

The Sheets names can vary each time I run the Macro.

Thanks in advance

Cfer
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Sandeep Warrier

Well-known Member
Joined
Oct 31, 2008
Messages
2,677
You can store the value in A1 in a variable

for example

Code:
Dim stSheetName As String
 
 stSheetName = Range("A1").Value
 ThisWorkbook.Sheets(stSheetName).Range("Q7").Value

This should work.
 
Upvote 0

Forum statistics

Threads
1,190,876
Messages
5,983,355
Members
439,840
Latest member
billy1989

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