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
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