PDA

View Full Version : error msg box



ashgull80
12-02-2014, 11:30 AM
hi
what could i put at the end of this code to show a msgbox if no match is found so that it doesnt come up with a runtime error?


Private Sub cboexpcompanyname_Change()

Dim TheValue As String
TheValue = frmAddExpend.cboexpcompanyname.Text

Dim TheSearch As Object
Dim TheRange As Range
Set Ws1 = Worksheets("Payee")
Set TheRange = Ws1.Range(Ws1.Cells(3, 3), Ws1.Cells(Ws1.UsedRange.Rows.Count, 1))
Set TheSearch = TheRange.Find(What:=TheValue, After:=TheRange.Cells(TheRange.Cells.Count), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

frmAddExpend.txtexpdescription.Value = Ws1.Cells(TheSearch.Row, 3)

End Sub

Thanks ash

Kenneth Hobs
12-02-2014, 12:09 PM
If TheSearch Is Nothing then
MsgBox "Search Error"
Exit Sub
End IF

snb
12-02-2014, 12:54 PM
Now the user can't make any 'mistakes'.


Private Sub Userform_initialize()
cboexpcompanyname.list=sheets("Payee").cells(1).currentregion.columns(3).value
End Sub


Private Sub cboexpcompanyname_Change()
frmAddExpend.txtexpdescription.Text = cboexpcompanyname.value
End Sub