How to switch between workbooks in vba? Working on one summary file and multiple workbooks.

ironny90

Board Regular
Joined
Mar 29, 2022
Messages
72
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone! This is the first week I learn VBA so forgive me if my questions are dumb. So I am working on multiple templates with one summary file (named "Test"). So I need to copy values from the summary file and paste to each individual workbooks. Cell A1 in each workbook contains the individual name, which is also in column A of the summary file.

My idea is to open each workbook, go to cell A1, get the value and search the value in the summary file, then offset from that cell to get the value I want, copy and paste to the individual workbook.

But I ran into error at the line in bold. Also how do I switch back to the other workbook since I activated the summary file called "Test"? I don't necessarily know each workbook name in test1 folder. They just run one by one... Let me know if you can help with how to proceed;) Thank you!

Sub Macro1()
Set fso = CreateObject("scripting.filesystemobject")
Set ff = fso.getfolder("C:\Users\34264\Desktop\training\Winston\Winston_1\test1")
For Each file In ff.Files
Workbooks.Open file
Sheets("Summary").Select
Range("A1").Select

rngY = Range("A1").Value

Workbooks("Test.xlsx").Activate -- error here
Sheets("test").Select
Columns("A:A").Select
Selection.Find(What:=rngY, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select


Next

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
oki, found solution to refer to the other open workbook, I can set wbk2 = activeworkbook and just refer to wbk2 going forward.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top