Vlook up if return Value is Nothing

mrsec

Board Regular
Joined
Jan 28, 2016
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello,

How do i put a something if lets say my return value is nothing(0) or blank in vlook up.

VBA Code:
Private Sub textboxProductID_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
On Error GoTo MyErrorHandler:
If KeyCode = vbKeyReturn Then
    Dim z As Double
    z = textboxProductID.Value
    textboxPrevious.Text = Application.WorksheetFunction.VLookup(z, Worksheets("Data").Range("TableRange"), 6, False) ----->"if False then it will show the Value that its looking for,if True to show "New Data" instead of just empty textbox.
               
    Else
End If
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
 MsgBox "New Data."
End If
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Something like this
VBA Code:
Private Sub textboxProductID_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

On Error GoTo errHandler
If KeyCode = vbKeyReturn Then
    Dim z As Double
    z = textboxProductID.Value
    textboxPrevious.Text = Application.WorksheetFunction.VLookup(z, Sheets("Data").Range("TableRange"), 6, False)
End If
If Me.textboxPrevious = "" Then Me.textboxPrevious = 1

errHandler:
If Err.Number = 1004 Then
    MsgBox "ID not in List"
    Me.textboxPrevious = ""
    Err.Clear
    Resume Next
End If

End Sub
 
Upvote 0
Solution
Something like this
VBA Code:
Private Sub textboxProductID_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

On Error GoTo errHandler
If KeyCode = vbKeyReturn Then
    Dim z As Double
    z = textboxProductID.Value
    textboxPrevious.Text = Application.WorksheetFunction.VLookup(z, Sheets("Data").Range("TableRange"), 6, False)
End If
If Me.textboxPrevious = "" Then Me.textboxPrevious = 1

errHandler:
If Err.Number = 1004 Then
    MsgBox "ID not in List"
    Me.textboxPrevious = ""
    Err.Clear
    Resume Next
End If

End Sub
Thanks again Zot
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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