double vlookup in excel vba

ENGinTraining

New Member
Joined
May 14, 2011
Messages
14
I attempting to search a table in excel for 2 variables. I already made a column containing both variables, formatted as "A|B".

The excel code would be =vlookup(state8s_p & "|" & state8s_s,'Table A-6E(P|s)'A6:H616!,5,False)

The above code works in a cell in excel, but I am trying to write it in Visual Basic, and in the cell it gives me a #Name? error. Any Idea why?

Code:

Function testdouble(state8s_p As Double, state8s_s As Double) As Double


Dim rA6E As Range
Dim orig_p As Double
Dim orig_p2 As Double
Dim dSideHi As Double
Dim dSideLo As Double
Dim dPresHi As Double
Dim dPresLo As Double


Set rA6E = Worksheets("Table A-6E(P|s)").Range("A6:H616")



orig_p = Application.VLookup(state8s_p + "|" + state8s_s, rA6E, 5, False)
testdouble = orig_p

End Function

There are a few extra variables, because this is only part of a larger program, but this is the part that is giving me an error.
 
How about changing the name to something simple, like "Bob"?
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
that actually worked... why is that? I just had some one help me in person and they said they believed it was because after I inserted a new module i renamed it to the same name of my function in the module?
 
Upvote 0
You don't want to do that.

As I said before, you should pass all data the function needs to return a result. Otherwide, Excel sees no dependency. So the first few lines should look like this:

Code:
Function sup_state8_hs(state8s_p As Double, state8s_s As Double, [COLOR=red]rA6E As Range[/COLOR]) As Double
    Dim orig_p      As Double
    Dim orig_p2     As Double
    Dim dSideHi     As Double
    Dim dSideLo     As Double
    Dim dPresHi     As Double
    Dim dPresLo     As Double
    Dim Count       As Long
 
    dPresHi = state8s_s
    dPresLo = state8s_s
 
    On Error Resume Next
 
    orig_p = Application.VLookup(state8s_p & "|" & state8s_s, rA6E, 5, False)
 
Last edited:
Upvote 0
ok its defiantly working now. Thank you for all the help. I guess I thought I was just changing a label of the module, not realizing it was the name and It mattered.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

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