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
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Scott T

Well-known Member
Joined
Dec 14, 2016
Messages
2,610
Office Version
365, 2016
Platform
Windows
Try
replacing
Code:
Sheetnames = shInput.Range("A1")

with
Code:
Sheetnames = Split(shInput.Range("A1"), ",")
This will select the 3 sheets
 

Watch MrExcel Video

Forum statistics

Threads
1,095,176
Messages
5,442,836
Members
405,201
Latest member
kashyap44

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top