Dear All,
I have this code that I've copied from somewhere. It works. I want the user to fill the field by typing. The problem is that if the user types a name that is not the list, excel returns an error because it does not find the value Rigaforn in the target range.
Private Sub CMBForn_Change()
Application.ScreenUpdating = False
'Trova riga fornitore
Dim Clienti As Worksheet
Set Clienti = Sheets("Clienti")
Set Cerca = Clienti.Range("B:B").Find(What:=Me.CMBForn.Value)
Dim RigaForn As Variant
RigaForn = Cerca.Row
'Copia dati
Dim BConf As Worksheet
Set BConf = Sheets("BConfirmation")
BConf.Unprotect "123"
BConf.Cells(10, 1) = Clienti.Cells(RigaForn, 2)
BConf.Cells(11, 1) = Clienti.Cells(RigaForn, 3)
BConf.Cells(12, 1) = Clienti.Cells(RigaForn, 4)
BConf.Cells(13, 1) = Clienti.Cells(RigaForn, 5)
BConf.Cells(13, 2) = Clienti.Cells(RigaForn, 6)
BConf.Cells(14, 1) = Clienti.Cells(RigaForn, 7)
BConf.Cells(15, 1) = Clienti.Cells(RigaForn, 8)
ActiveSheet.Protect "123", True, True
End Sub
I would like to know which code I should put after:
Set Cerca = Clienti.Range("B:B").Find(What:=Me.CMBForn.Value)
to avoid the error.
Something like on error... nothing should happen!
Thank you,
miami2k
I have this code that I've copied from somewhere. It works. I want the user to fill the field by typing. The problem is that if the user types a name that is not the list, excel returns an error because it does not find the value Rigaforn in the target range.
Private Sub CMBForn_Change()
Application.ScreenUpdating = False
'Trova riga fornitore
Dim Clienti As Worksheet
Set Clienti = Sheets("Clienti")
Set Cerca = Clienti.Range("B:B").Find(What:=Me.CMBForn.Value)
Dim RigaForn As Variant
RigaForn = Cerca.Row
'Copia dati
Dim BConf As Worksheet
Set BConf = Sheets("BConfirmation")
BConf.Unprotect "123"
BConf.Cells(10, 1) = Clienti.Cells(RigaForn, 2)
BConf.Cells(11, 1) = Clienti.Cells(RigaForn, 3)
BConf.Cells(12, 1) = Clienti.Cells(RigaForn, 4)
BConf.Cells(13, 1) = Clienti.Cells(RigaForn, 5)
BConf.Cells(13, 2) = Clienti.Cells(RigaForn, 6)
BConf.Cells(14, 1) = Clienti.Cells(RigaForn, 7)
BConf.Cells(15, 1) = Clienti.Cells(RigaForn, 8)
ActiveSheet.Protect "123", True, True
End Sub
I would like to know which code I should put after:
Set Cerca = Clienti.Range("B:B").Find(What:=Me.CMBForn.Value)
to avoid the error.
Something like on error... nothing should happen!
Thank you,
miami2k