VBA If Then Cell Value From Another Open Workbook

Mcook13

New Member
Joined
May 14, 2019
Messages
43
Hello Excel Wizards,

I am trying to write an If Then statement in VBA to have my workbook save in the appropriate file location depending on the cell value of another open workbook.

I have 2 open workbooks. The one workbook (call it "Wbk A") I am saving has to reference the cell value in the other open workbook (call it "Wbk B"). If Wbk B's cell value equals X, then Wbk A will follow a specific save file path. Or a different save file path if Wbk B's cell value equals Y.

The part I am having trouble writing is the portion of the code to say if Wbk B's cell value (in L2 to be exact) equals X....

I know how to write the Then portion since that is the save file path.

Thank you for any and all help!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Do you have the second workbook assigned to a Workbook object in your code? If so then

VBA Code:
If WbkB.Worksheets("MySheet").Range("L2") = "X" Then

If not then

VBA Code:
If Workbooks("Wbk B.xlsx").Worksheets("MySheet").Range("L2") = "X" Then

It's a pretty generic answer but then again the question is a bit generic. If you show the code you already have I could be more specific.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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