Well It worked fine at first and I don't know why It began to send me errors, I tried to fix it, and sometimes worked when I pasted the code again, but then began to fail, this is the complete code of the button, If you could tell me what I'm doing wrong I'd really appreciate it:
Private Sub RegCommandButton_Click()
Sheet1.Unprotect Password:="2606"
Dim emptyRow As Long
Dim vReturnVal As Variant
'Make sheet1 active
Sheet1.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
vReturnVal = Application.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:C"), 2, False)
If Not IsError(vReturnVal) Then
Cells(emptyRow, 5).Value = vReturnVal
Cells(emptyRow, 1).Value = Date
Cells(emptyRow, 2).Value = Time
Cells(emptyRow, 3).Value = SerieTextBox.Value
Cells(emptyRow, 4).Value = UserTextBox.Value
Cells(emptyRow, 6).Value = Application.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:D"), 3, False)
Cells(emptyRow, 7).Value = Application.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:E"), 4, False)
Cells(emptyRow, 8).Value = Application.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:F"), 5, False)
Else
CodeUserForm.Show
End If
ThisWorkbook.Save
Call UserForm_Initialize
End Sub
If you reference the Application object instead of the WorksheetFunction property, you'll get a non-breaking error when an error occurs. So you can test for an error as follows...
Code:
Dim vReturnVal As Variant
vReturnVal = Application.VLookup(CLng(SerieTextBox.Value), Sheets("RecordPrint").Range("B:C"), 2, False)
If Not IsError(vReturnVal) Then
Cells(emptyRow, 5).Value = vReturnVal
Else
'Do something else
End If
Hope this helps!