Hi All
I've been teaching myself VBA for the purpose of processing some time resolved data from an instrument. I've come up against a problem and I just can't work out why the code is failing. (using excel 2007, VBA 6.5)
I declare some arrays as dynamic, then ReDim them to a user defined number (with Option Base 1) and input data from a spreadsheet into the array. I can then output the data into the spreadsheet again and the lbound and ubound functions return the correct values for the array. What I cannot do is actually access individual elements. If I specify array(i) I get the "Subscript is out of range" error.
The code relevant to this problem is as below (simplified as there are more arrays):
Dim an171rw() As Double
Dim an171bc() As Double
Dim i As Integer
Dim y As Double 'Intervening lines left out
ReDim an171rw(1 To rowcount) 'rowcount is the user-defined variable
ReDim an171bc(1 To rowcount)
an171rw() = Range(Cells(AnStCell, col171), Cells(AnEdCell, col171)).Value
'assign cell values to array
Worksheets("Calculations").Range(Cells(AnStCell, 16), Cells(AnEdCell,16)).Value = an171rw
'outputs array to worksheet
an171bc = an171rw
Worksheets("Calculations").Range(Cells(AnStCell, 10), Cells(AnEdCell,10)).Value = an171bc
'used to check array has values and will then be used to check operations worked
For i = LBound(an171bc) To UBound(an171bc)
y = an171rw(i) * 2
' Error occurs at the above line, just an example of what I would like to do, will be extended
an171bc(i) = y
' and here if I comment out previous line
Next i
etc,etc
(The arrays in this example have 854 lines. so 1-854 are the bounds)
I have tried different methods for basically everything. Including ReDiming using only rowcount in brackets, not using y, using a For each loop. I tried just putting an integer in (e.g. an171rw(1)) and that has the same result.
I'm sure it is something simple but I just cannot figure out the problem. 
Thanks for any help
Bookmarks