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