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)
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)