ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Switching Between 2 workbooks using VBA (https://www.excelbanter.com/excel-programming/375286-switching-between-2-workbooks-using-vba.html)

Isit Ears[_2_]

Switching Between 2 workbooks using VBA
 
How do you switch between 2 open workbooks using a macro. Both workbooks
would already be open but I need to be able to pick a value from one, then
look for it in the 2nd workbook and then repeat.

Thanks

Gary''s Student

Switching Between 2 workbooks using VBA
 
The following gets a value from Book1 and looks for it in Book2:

Sub demo()
Dim r1 As Range
Dim r2 As Range
Set r1 = Workbooks("Book1").Worksheets("Sheet1").Range("A1" )
v = r1.Value
Workbooks("Book2").Activate
Sheets("Sheet1").Activate
For Each r In ActiveSheet.UsedRange
If r.Value = v Then
MsgBox (r.Address)
Exit For
End If
Next
End Sub

using Sheet1 in both books
--
Gary's Student


"Isit Ears" wrote:

How do you switch between 2 open workbooks using a macro. Both workbooks
would already be open but I need to be able to pick a value from one, then
look for it in the 2nd workbook and then repeat.

Thanks



All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com