I am creating a macro which will select sheets from a larger workbook, move and save those sheets as a new workbook, and then move onto the next set.
I have created a pseudo "array" with start and end values (designated by sheet index numbers).
I am encountering a "Subscript out of range" error after completing the section that saves the file, but before the loop which would pull the next set of worksheets.
Below is my code. Any help with this error would be appreciated.
Dim Start As Integer
Dim Finish As Integer
Dim SR As Integer
Dim SC As Integer
Dim ER As Integer
Dim EC As Integer
SR = 2
SC = 5
ER = 2
EC = 6
Start = Sheets("REF").Cells(SR, SC).Value
Finish = Sheets("REF").Cells(ER, EC).Value
Dim sheetArray() As Double
Dim i As Integer
Dim c As Integer
i = 0
c = Start
lastrow = Cells(100, SC).End(xlUp).Row
Do Until SR = lastrow
Do Until c > Finish
ReDim Preserve sheetarray (0 to i)
i = i + 1
c = c + 1
Loop
Sheets(sheetarray).Copy
ActiveWorkbook.SaveAs Filename:= _ XXXXXXXXXXXXXXXXXX
C = Start
i = 0
SR = SR + 1
ER = ER + 1
Loop
EDIT: 16:35 Central US
Currently, the relevant code block matches what is above, through the line lastrow = Cells(100, SC).End(xlUp).Row
Do Until SR = lastrow
ReDim sheetArray(i)
Do Until c > Finish
ReDim Preserve sheetArray(i)
sheetArray(i) = c
i = i + 1
c = c + 1
Loop
Sheets(sheetArray).Copy
ActiveWorkbook.SaveAs Filename:= _
XXXXXXXXXXXXX
c = Start
i = 0
SR = SR + 1
ER = ER + 1
Loop
sheetarray
before trying to create it again before starting another loop – Scott Holtzman