Attempting to copy a range from one workbook to another - there will be other tasks performed on the data set in the process but this is the gist of what I want for now. The range in the source workbook is not static; meaning each time a report is generated, the necessary information will appear in the same columns but not the same rows. There is one blank column in the middle of the range and several columns I will be ignoring - along with some calculations/converting of data. To try and help with the somewhat unpredictable nature of the location of the data in the source workbook, I've named my range as a variable in the sub - I'm not sure if that is the problem. Everything seems to be working out, except when I go to put the range in the array. Here's what I've got:
Sub GetElemArray()
Dim fndrng As Range
Dim rEleAn As Range
Dim frst As Range
'the rest of the variables below are global
Workbooks(SheetName).Activate
Worksheets("Report").Activate
Columns(2).Select
Set fndrng = Selection.Find("Analyte")
Set frst = fndrng.Offset(1, 0)
Set rEleAn = Range(frst, fndrng.End(xlDown).End(xlToRight))
EleList = rEleAn.Rows.Count
ColList = rEleAn.Columns.Count
ReDim ElAr(0 To EleList, 0 To ColList)
For EleList = LBound(ElAR, 1) To UBound(ElAr, 1)
For ColList = LBound(ElAr, 2) To UBound(ElAr, 2)
'The following line returns the Runtime 1004 error
ElAr(EleList, ColList) = Range(frst).Offset(EleList, _
ColList).Value
Next ColList
Next EleList
Code to Do Other Stuff
End Sub
Looking through the Locals Window, I can see that rEleAn
stores its values as .Value2
. I tried changing the Range to this property and it still returned the same error. Looking in the Locals Window, everything is assigned properly near as I can tell.
Any ideas as to what is happening?