Not an Excel/VB expert but I keep getting
Run time error: 9: Subscript out of range
The error is occurring at the For Each
line. Not sure why. I'm trying to copy worksheets from one workbook to another workbook.
The Workbook strFileName
is being open successfully and the workbook does contain two other worksheets but code is failing on next line. I've seen similar posts regarding similar issue but have not had any luck. Any advice would be great. (I'm using Excel 2010) Thanks
Workbooks.Open (strFileName)
For Each sheet In Workbooks(strFileName).Worksheets
total = Workbooks(activeWKBook).Worksheets.Count
Workbooks(strFileName).Worksheets(sheet.Name).Copy _
after:=Workbooks(activeWKBook).Worksheets(total)
Next sheet
Workbooks(strFileName).Worksheets(sheet.Name).Copy after:=Workbooks(activeWKBook).Sheets(Sheets.Count)
– Saagar Elias Jacky