VBA Code - Formula from one workbook to another

Mai_Mai

New Member
Joined
May 8, 2014
Messages
2
Hi,

Need help. I am an excel macro newbie. I want this formula from my current workbook to lookup for values of G4 to another workbook. The another workbook file name is in the current workbook A1 cell. Here's my code.

Dim otherWB As Workbook

Set otherWB = Workbooks(Sheets("Pivot").Range("a1").Value)

Sheets("Pivot").Select
With Range("H4")
.Formula = "=IF(G4<>"""",IFERROR(VLOOKUP(G4,'[sourceWB]Detail'!E:J,1,FALSE),""For Addition""),"""")"
.Copy Destination:=Range(.Offset(0, -1), .Offset(0, -1).End(xlDown)).Offset(0, 1)
End With

The formula seems to work fine but the problem is the UpdateValues:otherWB dialog box is keep on prompting to locate my file even the file is already open. How can I elimanate the prompting of the updatevalues dialog box?

Thanks in advance.

Regards,
MaiMai:confused:
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The formula seems to work fine but the problem is the UpdateValues:otherWB dialog box is keep on prompting to locate my file even the file is already open. How can I elimanate the prompting of the updatevalues dialog box?

Perhaps take a look at:
File | Options | Advanced | Scroll down and disable (uncheck) the reference to other workbooks or external references.
 
Upvote 0
Perhaps take a look at:
File | Options | Advanced | Scroll down and disable (uncheck) the reference to other workbooks or external references.

Thanks for the help strooman, but it doesn't work:(.

I stand corrected with my formula it should be

.Formula = "=IF(G4<>"""",IFERROR(VLOOKUP(G4,'[otherWB]Detail'!E:J,1,FALSE),""For Addition""),"""")"

forgot to change it when I paste the code.
 
Upvote 0

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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