I have a two sheet workbook with sheets("input") and sheets("output"). I'm trying to pass a particular range of data from sheets("output") to an array while I'm on sheets("input") but keep getting a Run-time error '1004': Method 'Range' of object'_worksheet failed.

Code works fine if sheets("output") is activated first.

Any guidance on how to pass this data without activating sheets("output") first?


Dim ws As Worksheet
Dim vArray() As Variant
    
Dim x as integer, y as integer, z as integer
Dim vArray() As Variant

Set ws = Sheets("output")

' actual values for x,y,z are established in sheets("input") and will vary
x = 1
y = 4
z = 4

vArray = ws.Range(Cells(x, 1), Cells(z, y)).Value
Thanks.