View Single Post
 
Old 09-06-2018, 10:28 PM
Josh1012 Josh1012 is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Sep 2018
Posts: 12
Josh1012 is on a distinguished road
Default How to Loop through all open Workbboks

Hi,

I'm trying to loop through all open workbooks excluding the one I'm working in as the master workbook and want to copy the first two cells (A1:A2) in each workbook in each sheet, back to the workbook that I'm working in.

Here is the code I have so far, but I keep getting a runtime error '438':


Sub Macro1()
'
' Macro1 Macro
'
Dim wb As Workbook
Dim ws As Worksheet
Dim myrange As Range
Dim i As Long

For Each wb In Application.Workbooks
If wb.Name <> "Book1.xlsx" Then
For Each ws In wb.Sheets()
For i = 3 To i + 2
ws.Range("A1:A2").Copy Destination:=Windows("Book1").Sheets("Sheet1").Ran ge(Cells(i, 1), Cells((i + 1), 1)).String
Next i
Next ws
End If
Next wb
End Sub
Reply With Quote