Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-06-2018, 10:28 PM
Josh1012 Josh1012 is offline How to Loop through all open Workbboks Windows 10 How to Loop through all open Workbboks Office 2010 64bit
Novice
How to Loop through all open Workbboks
 
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
 

Tags
copy, for each loop, for loop

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Loop through all open Workbboks Do Loop bug donlincolnmsof Word VBA 11 09-07-2017 10:07 PM
How to Loop through all open Workbboks Macro Loop Help Twizzle008 Word VBA 15 09-18-2015 03:20 PM
What's wrong with my loop? Irrma Word VBA 2 06-17-2014 06:25 AM
How to Loop through all open Workbboks How to a For loop in VBA Jennifer Murphy Word VBA 1 01-29-2013 03:30 AM
How to Loop through all open Workbboks Continuous Loop cksm4 Word 6 01-06-2011 09:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft