VBA Form Macro VLookup if not found...

epardo87

Board Regular
Joined
Feb 24, 2015
Messages
56
Hello,

I'm building a VBA form where I require only two fields to be typed, afterwards when hitting a record button, they are transferred into sheet1, now that works fine. In sheet2 ("RecordPrint") some data is previously filled, and I require that other cells in sheet1 VLookup data recorded in sheet2 with one of the fields typed, that also works fine but only when the number typed in the form is found in sheet2.

The problem is that when the Macro doesn't find the number typed, it pops up a window about Run-time "13" asking me to end or debug, If I hit end, it closes but it transfers all fields typed without the data that VLookup should have pulled.

What I would like is that when the number is not found in sheet2 it popped up a window notifying that the number is incorrect and that it doesn't transfers any data to sheet1.

These are the transfer codes:

'Transfer information
Cells(emptyRow, 1).Value = Date
Cells(emptyRow, 2).Value = Time
Cells(emptyRow, 3).Value = SerieTextBox.Value
Cells(emptyRow, 4).Value = UserTextBox.Value
Cells(emptyRow, 5).Value = WorksheetFunction.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:C"), 2, False)
Cells(emptyRow, 6).Value = WorksheetFunction.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:D"), 3, False)
Cells(emptyRow, 7).Value = WorksheetFunction.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:E"), 4, False)
Cells(emptyRow, 8).Value = WorksheetFunction.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:F"), 5, False)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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