VBA VLOOKUP returning zero value due to data type mismatch.

papermonkey

New Member
Joined
Jun 25, 2018
Messages
5
Hi,


am using below function and always getting value zero for .
i even tried changing cell formats for datarange, when i do that i get 13 type mismatch error. please help.


If Trim(CStr(TextBox_itemcode.Text)) <> "" Then
myitval = mylookup(Trim(CStr(TextBox_itemcode.Text)))
Worksheets("SALES").Activate
Range("amt_tot").Rows(ZeileA).Value = myitval
Else
Range("amt_tot").Rows(ZeileA).Value = "9999.99"
End If








Function mylookup(itemcode As String) As Double
Dim myrange As Range
Dim myvalue As Double
Set myrange = Worksheets("Items sales").Range("G24:F1000")
Worksheets("Items sales").Activate
myitval = [Application.WorksheetFunction.SVERWEIS(itemcode, myrange, 5, False)]
If IsError(myvalue) = True Then
myvalue = 9999.99
End If
End Function


please help.
if possible also please suggest me how to convert this vlookup into index match.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
can you try changing to ByVal by defult it's ByRef.

Function mylookup(ByVal itemcode As String) As Double
Dim myrange As Range
Dim myvalue As Double
Set myrange = Worksheets("Items sales").Range("G24:F1000")
Worksheets("Items sales").Activate
myitval = [Application.WorksheetFunction.SVERWEIS(itemcode, myrange, 5, False)]
If IsError(myvalue) = True Then
myvalue = 9999.99
End If
End Function
 
Last edited:
Upvote 0
and try this piece of code and let me know if it works

Code:
Sub Vlookup()
Dim itemCode
Dim myRange As Range
Dim oResult


Set myRange = Worksheets("Sheet1").Range("A:B")  ' '''''Change Sheet name and range
itemCode = "00A1B"  '''' change this lookup value
On Error GoTo ErrFound
oResult = [ WorksheetFunction.SVERWEIS(itemCode, myRange, 1, 0)]


MsgBox oResult
Exit Sub


ErrFound:
MsgBox Err.Number
If Err.Number = 1004 Then
    MsgBox " Value not found"
End If
End Sub



You should have mentioned that you are using German version Excel , took me while to figured out what is "[COLOR=#333333]SVERWEIS"[/COLOR]:)
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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