Using Index function in userform

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Please I need your help

I'm trying to find a value reference to two columns, I'v tried it in Excel worksheet, it works fine, but I'm not able to use it in VBA

Here is the function that I tested in Excel worksheet in range (I2) and works fine

=INDEX(E:E,MATCH(1,(A:A=G2)*(B:B=H2),0))


[TABLE="width: 800"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Inv. #[/TD]
[TD]Num[/TD]
[TD]BarCode[/TD]
[TD]Name[/TD]
[TD]Cost[/TD]
[TD][/TD]
[TD]Inv. #[/TD]
[TD]Num[/TD]
[TD]Cost[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]101[/TD]
[TD]1[/TD]
[TD]111[/TD]
[TD]Test1[/TD]
[TD]10[/TD]
[TD][/TD]
[TD]102[/TD]
[TD]3[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]101[/TD]
[TD]2[/TD]
[TD]222[/TD]
[TD]Test2[/TD]
[TD]20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]102[/TD]
[TD]1[/TD]
[TD]111[/TD]
[TD]Test1[/TD]
[TD]10[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]102[/TD]
[TD]2[/TD]
[TD]222[/TD]
[TD]Test2[/TD]
[TD]20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]102[/TD]
[TD]3[/TD]
[TD]333[/TD]
[TD]Test3[/TD]
[TD]30[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I tried to use it in my userform but I get an error

Here is the code I tried

Code:
Dim ws As Worksheet
Set ws = Sheet6


Set findvalue = Application.WorksheetFunction.Index(ws.Range("E:E"), Match(1, (ws.Range("A:A") = Me.List_Sales.Value) * (ws.Range("B:B") = Me.List_Details.Value), 0))
Me.txtReturn = findvalue


Can someone please help me how make it correct?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Assuming your findvalue variable is not an object, try removing the "Set" keyword.
 
Upvote 0
Assuming your findvalue variable is not an object, try removing the "Set" keyword.

Also, the use of Match in your code line won't work as it is not a built-in VBA function... you will have to affix a call to the WorksheetFunction object for it like you did for the Index call.
 
Upvote 0
Actually I did it the same as Vlookup works but I'm not sure about it,

Can you please help me how to get the result I need even with another way?
 
Upvote 0
Also, the use of Match in your code line won't work as it is not a built-in VBA function... you will have to affix a call to the WorksheetFunction object for it like you did for the Index call.


Hello Rick Rothstein,

Can you please help me fixing my problem? I'm new with VBA and still didn't get any solution, please I need your help
 
Upvote 0
How about
Code:
Dim ws As Worksheet
Dim FindValue As Variant
Set ws = Sheet6


FindValue = Application.Index(ws.Range("E:E"), Application.Match(1, (ws.Range("A:A") = Val(Me.List_Sales.Value)) * (ws.Range("B:B") = Val(Me.List_Details.Value)), 0))
If Not IsError(FindValue) Then
   Me.txtReturn = FindValue
Else
   Me.txtReturn = "Not found"
End If
 
Upvote 0
Thanks for your time Fluff, but I still get an error (Run-time error '13': Type mismatch)
 
Upvote 0
What are you entering into
List_Sales and List_Details
are they text or numerical?
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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