Set Command For a Worksheet

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
816
I have a cell in my spreadsheet that I have given the range name "Sh1_Name". Currently the value in the cell is the word "Product".

In my macro I want to tell Excel to set OpsSht(1) to the "Product" worksheet, but cannot come up with the right code. I have...

Dim OpsSht(10) As Worksheet
Set OpsSht(1) = Sheets(Range("Sh1_Name"))

... but the second line does not work. Could someone help?

Thanks,

MikeG
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
Mike,

Are OpsSht 10 and OpsSht 1 the same thing?

Dim OpsSht1 as Worksheet
Set OpsSht1 = Worksheets("Product")
 

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
816
Mike,

Are OpsSht 10 and OpsSht 1 the same thing?

Dim OpsSht1 as Worksheet
Set OpsSht1 = Worksheets("Product")

Thanks Dryver.

Actual they are not. I have 9 other sheets so for example I want OpsSht(1) as "Product", OpsSht(2) as "Customer" and so on. But I want the user to be able to define these names in the spreadsheet, not in the macro - because the names can change from time to time.

Mike
 

Watch MrExcel Video

Forum statistics

Threads
1,123,535
Messages
5,602,217
Members
414,513
Latest member
junbuggle

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