Selecting sheets based on value in cell

StianU

New Member
Joined
Jan 25, 2019
Messages
4
Hi,

I have a workbook where I want to print selected sheets, based on worksheets named in a cell i Excel.
In cell A1 in Worksheet1 I have the names of the sheets I want to select, seperated by comma. The value in cell A1 is "Report1,Report2,Report3" and so on, and it changes based on inputs in different cells.

I have tried this formula, but I get Runtime error 9. Anyone what am I doing wrong?

Sub SelectSheets()
Dim wrLocal As Workbook
Dim shInput As Worksheet
Dim Sheetnames As Variant

Set wrLocal = ThisWorkbook
Set shInput = wrLocal.Worksheets("INPUT")

Sheetnames = shInput.Range("A1")
Sheetnames = Application.WorksheetFunction.Transpose(Sheetnames)
Worksheets(Sheetnames).Select

End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try
replacing
Code:
Sheetnames = shInput.Range("A1")


with
Code:
Sheetnames = Split(shInput.Range("A1"), ",")

This will select the 3 sheets
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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