Vlookup using VBA Constants

seahawk56

New Member
Joined
Jun 23, 2008
Messages
30
I want to use a VLOOKUP formula to pull data from additional workbooks. I would like to use constants/dimensions in VBA to reference the “table_array” in the formula. The pathways will always stay the same but the name will change to the date. The formula will bring back the data but I have to select the workbook each time. Is there any helpful hints to make it work? Or is this a limitation of the VLOOKUP?
Formula:
"=IF(ISERROR(VLOOKUP($P120,MyStaff1!MonProd,3,FALSE)),0,VLOOKUP($P120,MyStaff1!MonProd,3,FALSE))"

Code:
Public Const MyFile As String = "OPLdailyworkplanning"
Public Const MyLoc As String = "G:\ROC-CLAIMS\Clms Proc-Model Line\DMS\OPL\Planned Work\"
Public Const MyProdFile As String = "ProdTrack"
Public Const MyProdLoc As String = "G:\ROC-CLAIMS\Clms Proc-Model Line\DMS\OPL\Production Tracking\"
Public Const MyTempLoc As String = "G:\ROC-CLAIMS\Clms Proc-Model Line\DMS\OPL\Production Tracking\Templates"
Public Const MyTempFile As String = "ProdTrack_Template.xls"
StaffName1 = ActiveSheet.Range("A3").Value
MyWeek = " " & MyProdFile & "_" & ConvertToJulian(ActiveSheet.Range("D1").Value) & "_" & ConvertToJulian(ActiveSheet.Range("E1").Value) & ".xls"
MyStaff1 = MyProdLoc & StaffName1 & "\" & StaffName1 & MyWeek

 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I don't know what that code has to do with VLOOKUP, but it is straightforward, use

Code:
    If IsError Application.VLOOKUP(Range("P120").Value,Workbooks("thatbook.xls").Worksheets("thatSheet").Range("M1:P50"),3,False) Then

        myVal = ""
Else

        myVal = Application.VLOOKUP(Range("P120").Value,Workbooks("thatbook.xls").Worksheets("thatSheet").Range("M1:P50"),3,False)
End If
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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