Feb 18 2022 09:36 AM
Hi I have a macro to calculate a textbox value. It's wroking but when I erase txtValorVenal value with backspace gives me error when value is "2" for example.
How do I treat this error?
Sub ITBI()
On Error GoTo Erro
Dim x As Double
If Len(Userform1.txtValorArremat.Value) > 0 And Userform1.txtValorVenal.Value > 0 And Userform1.txtValorVenal.Value > Userform1.txtValorArremat.Value Then
x = (Userform1.cmbITBI.Value / 100) * Userform1.txtValorVenal.Value
Else
If Len(Userform1.txtValorArremat.Value) > 0 And Userform1.txtValorVenal.Value > 0 And Userform1.txtValorVenal.Value < Userform1.txtValorArremat.Value Then
x = (Userform1.cmbITBI.Value / 100) * Userform1.txtValorArremat.Value
Else
x = 0
End If
End If
If x > 0 Then
Userform1.txtITBI = x
Userform1.txtITBI.Value = VBA.Format(x, "R$ #,###0.00")
Else
Userform1.txtITBI.Value = Empty
End If
Exit Sub
Erro: MsgBox "Erro!", vbCritical, "VALOR"
End Sub