Good day. I was trying to print preview multiple sheets using an array. I was trying to set an array to a range and using the print preview function that way. Unfortunately it did not work.
The thing i used below:
Dim MyArray As Variant
MyArray = ThisWorkbook.Sheets("Admin Sheet").Range("A1:A2")
'A1 is "Sheet 1" and A2 is "Sheet 2"
ThisWorkbook.Sheets(Array(MyArray)).PrintPreview
Print Preview Multiple Sheets
Column
You need to pass a 1D array without the use of the
Arrayfunction. You can use the late-bound version of theTransposeworksheet function to convert the 2D array to a 1D array using the following:Here
MyArrayholds a 1D one-based array.Row
If you have the sheet names in a row (e.g.
A1:B1), you need to wrap the right side of theMyArray = ...expression in yet anotherApplication.Transpose():Here
MyArrayholds a 1D one-based array.Arrays
MyArray = ThisWorkbook.Sheets("Admin Sheet").Range("A1:A2").Valuereturns a 2D one-based (single-column) array held by theMyArrayvariable. You can prove it with the following:MyArray = Application.Transpose(wb.Sheets("Admin Sheet").Range("A1:A2").Value)will return a 1D one-based array held by theMyArrayvariable. You can prove it with the following:Dim Jag As Variant: Jag = Array(MyArray)returns the 1DMyArrayin the first and only element of another 1D (usually) zero-based array held by theJagvariable. This structure is called a jagged array or an array of arrays. You can prove it using the following: