"Subscript out of range" means you're accessing an array/collection beyond its boundaries.
Workbooks(i).Worksheets("Sheet2").Range("A1").Value = Workbooks(i).Worksheets("Sheet1").Range("B9:E111").Value
I count several different places in that single instruction that could throw that error. Split it up.
Dim book As Workbook
' if it blows up here, check how many books you have open:
Set book = Workbooks(i) 'consider looping from 1 To Workbooks.Count instead of 1 To 6
Dim source As Worksheet
' if it blows up here, check the filename of the book and whether it has a "Sheet1":
Set source = book.Worksheets("Sheet1")
Dim destination As Worksheet
' if it blows up here, check the filename of the book and whether it has a "Sheet2":
Set destination = book.Worksheets("Sheet2")
' when it blows up here, consider exactly what you're trying to do:
destination.Range("A1").Value = source.Range("B9:E111").Value
The last instruction looks suspicious to me. If you're trying to paste Sheet1!B9:E111
into Sheet2!A1
, consider using Copy
+PasteSpecial
as in Shai Rado's answer.
If you mean to iterate all open workbooks, consider a For Each
loop instead:
Dim book As Workbook
For Each book In Workbooks
'...
Next