Hi folks,
I did look at the other threads about this but couldn't find an answer within.
My situation is as follows. I have a sheet that generates a list of file names to be imported into different sheets, I'm writing code to loop through the sheets and import them all into each (each list of files is in a different column named after the sheet the files will be imported into). I think I've got my head around most of it, but when my macro gets to the import stage it says "subscript out of range" on the array that holds all the file names (DataFiles).
This part of my code that highlights when I hit debug.
This is how the array is populated:
My code worked before I used the With... function to populate the array, I was doing that manually before.
I did look at the other threads about this but couldn't find an answer within.
My situation is as follows. I have a sheet that generates a list of file names to be imported into different sheets, I'm writing code to loop through the sheets and import them all into each (each list of files is in a different column named after the sheet the files will be imported into). I think I've got my head around most of it, but when my macro gets to the import stage it says "subscript out of range" on the array that holds all the file names (DataFiles).
This part of my code that highlights when I hit debug.
Code:
For DFCounter = 0 To NoOfProducts
[COLOR=SeaGreen]'File Import/Data Connection[/COLOR]
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Macintosh HD:Users:user:path:" & DataFiles(DFCounter) & ".csv", _
Destination:=ImportTarget)
.LotsOfProperties = Variables
End With
Code:
With Sheets("Inputs_DataIDs").Range(DataColumns(SetCounter) & 2, DataColumns(SetCounter) & NoOfProducts + 1)
ReDim DataFiles(0 To NoOfProducts)
DataFiles = Range(DataColumns(SetCounter) & 2, DataColumns(SetCounter) & NoOfProducts + 1)
End With