Question

I'm trying to open up a series of xlm files stored in an array, but the error keeps popping up that says that the subscript is out of range. Any advice? Thanks

 Dim AllFiles() As String
 Dim count, test, StartRow, LastRow, LastColumn As Long    
 test = count
 Do While (test >= 0)
 Workbooks.Open Filename:=AllFiles(test) 'subscript out of range
 test = test - 1
 Loop
Was it helpful?

Solution

This doesn't address the root cause (what ever that may be) but is a more natural way to loop an array

For test = UBound(AllFiles) to LBound(AllFiles) Step -1    
    Workbooks.Open Filename:=AllFiles(test)
Loop

By the way, your dim statement Dim count, test, StartRow, LastRow, LastColumn As Long declares all items except LastColumn as Variant

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top