Have a vba userform that searches a list of serial numbers and populates details associated with that serial number. If the search textbox is left empty, a message box pops up advising to add a serial number, but then populates a result for any blank/empty cells in the serial number range (which I do not want it to do).
Essentially I want the form to yield no results at all if no serial is added in the search box.
How do I stop it from seeing blank cells as a viable result?
Very new to VBA.
Thank you for any help.
Essentially I want the form to yield no results at all if no serial is added in the search box.
How do I stop it from seeing blank cells as a viable result?
VBA Code:
Private Sub cmdsearch_Click()
Dim SERIAL As String
If txttxserial.Text = "" Then
Msg = "You must enter a serial number!"
MsgBox Msg
Me.txttxserial.SetFocus
End If
SERIAL = Trim(txttxserial.Text)
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Sheet1").Cells(i, 4).Value = SERIAL Then
txtTXmakemodel.Text = Worksheets("Sheet1").Cells(i, 2).Value & Space(1) & Worksheets("Sheet1").Cells(i, 3).Value
txtTXdate.Text = Worksheets("Sheet1").Cells(i, 10).Value
txttxwho.Text = Worksheets("Sheet1").Cells(i, 11).Value
txtadlic.Text = Worksheets("Sheet1").Cells(i, 12).Value
txtnotes.Text = Worksheets("Sheet1").Cells(i, 13).Value
End If
Next
End Sub
Very new to VBA.
Thank you for any help.