Need to treat erros

%3CLINGO-SUB%20id%3D%22lingo-sub-3185421%22%20slang%3D%22en-US%22%3ENeed%20to%20treat%20erros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3185421%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20I%20have%20a%20macro%20to%20calculate%20a%20textbox%20value.%20It's%20wroking%20but%20when%20I%20erase%26nbsp%3BtxtValorVenal%20value%20with%20backspace%20gives%20me%20error%20when%20value%20is%20%222%22%20for%20example.%3C%2FP%3E%3CP%3EHow%20do%20I%20treat%20this%20error%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20ITBI()%3C%2FP%3E%3CP%3EOn%20Error%20GoTo%20Erro%3CBR%20%2F%3EDim%20x%20As%20Double%3C%2FP%3E%3CP%3EIf%20Len(Userform1.txtValorArremat.Value)%20%26gt%3B%200%20And%20Userform1.txtValorVenal.Value%20%26gt%3B%200%20And%20Userform1.txtValorVenal.Value%20%26gt%3B%20Userform1.txtValorArremat.Value%20Then%3CBR%20%2F%3Ex%20%3D%20(Userform1.cmbITBI.Value%20%2F%20100)%20*%20Userform1.txtValorVenal.Value%3CBR%20%2F%3EElse%3C%2FP%3E%3CP%3EIf%20Len(Userform1.txtValorArremat.Value)%20%26gt%3B%200%20And%20Userform1.txtValorVenal.Value%20%26gt%3B%200%20And%20Userform1.txtValorVenal.Value%20%26lt%3B%20Userform1.txtValorArremat.Value%20Then%3CBR%20%2F%3Ex%20%3D%20(Userform1.cmbITBI.Value%20%2F%20100)%20*%20Userform1.txtValorArremat.Value%3CBR%20%2F%3EElse%3CBR%20%2F%3Ex%20%3D%200%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%3CP%3EIf%20x%20%26gt%3B%200%20Then%3CBR%20%2F%3EUserform1.txtITBI%20%3D%20x%3CBR%20%2F%3EUserform1.txtITBI.Value%20%3D%20VBA.Format(x%2C%20%22R%24%20%23%2C%23%23%230.00%22)%3C%2FP%3E%3CP%3EElse%3CBR%20%2F%3EUserform1.txtITBI.Value%20%3D%20Empty%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%3CP%3EExit%20Sub%3CBR%20%2F%3EErro%3A%20MsgBox%20%22Erro!%22%2C%20vbCritical%2C%20%22VALOR%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3185421%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

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

 

 

 

0 Replies