kevin chan
New Member
- Joined
- Aug 3, 2018
- Messages
- 3
I have this code which reads data into an array.
For some reason this works:
But this fails on the "pricedata=" line:
The key difference is in the pricedata = line. It refers to a different worksheet
I am trying to read a contiguous block of data into an array, but I can get it to work on the same worksheet but not if it refers to another worksheet.
DATASHEET is a global constant in this case with the sheet name.
Can anyone help me with an alternative way to code this?
Thanks!
For some reason this works:
Code:
Function TotalCost(col As Integer) As Double
Dim pricedata As Variant
Dim maxrows as Integer
maxrows = Worksheets(DATASHEET).Cells(Worksheets(DATASHEET).Rows.Count, col).End(xlUp).row
pricedata = Range(Cells(1, col), Cells(maxrows, col + 5)).Value
code goes on….
Code:
Function TotalCost(col As Integer) As Double
Dim pricedata As Variant
Dim maxrows as Integer
maxrows = Worksheets(DATASHEET).Cells(Worksheets(DATASHEET).Rows.Count, col).End(xlUp).row
pricedata = Worksheets(DATASHEET).Range(Cells(1, col), Cells(maxrows, col + 5)).Value
code goes on…
The key difference is in the pricedata = line. It refers to a different worksheet
I am trying to read a contiguous block of data into an array, but I can get it to work on the same worksheet but not if it refers to another worksheet.
DATASHEET is a global constant in this case with the sheet name.
Can anyone help me with an alternative way to code this?
Thanks!