jonastiger
Member
Hi I have an issue in a userform I can't solve and need help for that, if possible.
When insert value in tb21 (IVA), return "Run-time error '13': Type mismatch
tb25 (VALOR C/DESCONTO) and tb27 (VALOR FINAL) show upsomething weird:
tb25 should return €44,62 (€52,50-€7,88)
tb27 should return €54,88 (€44,62+€10,26) - €10,26 is the result from tb21*tb25, if "...type mismatch" doesn't happen
Please see the image:
Herés the code:
Thanks in advance
JT
When insert value in tb21 (IVA), return "Run-time error '13': Type mismatch
tb25 (VALOR C/DESCONTO) and tb27 (VALOR FINAL) show upsomething weird:
tb25 should return €44,62 (€52,50-€7,88)
tb27 should return €54,88 (€44,62+€10,26) - €10,26 is the result from tb21*tb25, if "...type mismatch" doesn't happen
Please see the image:
Herés the code:
Code:
Private Sub UserForm_Initialize()
' Add Items "UN" And "M2" to cb1
cb1.AddItem "UN"
cb1.AddItem "M2"
' Initialize TextBoxes
tb16.Value = Format(0, "0.00")'COMP (cm)'
tb17.Value = Format(0, "0.00")'LARG (m)'
tb18.Value = Format(0, "0")'UNID'
tb19.Value = Format(0, "€#,##0.00")'PREÇO UNIT'
tb20.Value = Format(0, "0%")'DESCONTO'
tb21.Value = Format(0, "0%")'IVA'
tb22.Value = Format(0, "0.00")'ÁREA/UN'
tb23.Value = Format(0, "€#,##0.00")'VALOR S/ DESCONTO'
tb24.Value = Format(0, "€#,##0.00")'VALOR DESCONTO'
tb25.Value = Format(0, "€#,##0.00")'VALOR COM DESCONTO'
tb26.Value = Format(0, "€#,##0.00")'VALOR IVA'
tb27.Value = Format(0, "€#,##0.00")'VALOR FINAL'
' Set TextBoxes ForeColor
tb16.ForeColor = &H808080
tb17.ForeColor = &H808080
tb18.ForeColor = &H808080
tb19.ForeColor = &H808080
tb20.ForeColor = &H808080
tb21.ForeColor = &H808080
tb22.ForeColor = &H808080
tb23.ForeColor = &H808080
tb24.ForeColor = &H808080
tb25.ForeColor = &H808080
tb26.ForeColor = &H808080
tb27.ForeColor = &H808080
End Sub
Private Sub cb1_Change()
If cb1.Value = "UN" Then
tb16.Enabled = False
tb17.Enabled = False
tb18.Enabled = True
tb16.BackColor = &HC0C0C0
tb17.BackColor = &HC0C0C0
tb18.SetFocus
ElseIf cb1.Value = "M2" Then
tb16.Enabled = True
tb17.Enabled = True
tb18.Enabled = False
tb18.BackColor = &HC0C0C0
tb16.SetFocus
End If
End Sub
Private Sub tb16_Change()
CalculateValues
End Sub
Private Sub tb17_Change()
CalculateValues
End Sub
Private Sub tb18_Change()
CalculateValues
End Sub
Private Sub tb19_Change()
CalculateValues
End Sub
Private Sub tb20_Change()
CalculateValues
End Sub
Private Sub tb21_Change()
CalculateValues
End Sub
Private Sub CalculateValues()
' Tb22
If tb16.Enabled And tb17.Enabled Then
tb22.Value = Format((Val(tb16.Value) / 100) * (Val(tb17.Value) / 100), "0.00")
ElseIf tb18.Enabled Then
tb22.Value = Val(tb18.Value)
End If
' tb23
tb23.Value = Format(tb22.Value * Val(tb19.Value), "€#,##0.00")
' tb24
If Val(tb20.Value) > 0 Then
tb24.Value = Format(tb23.Value * Val(tb20.Value) / 100, "€#,##0.00")
Else
tb24.Value = Format(0, "€#,##0.00")
End If
' tb25
tb25.Value = Format(tb23.Value + tb24.Value, "€#,##0.00")
' tb26
If Val(tb21.Value) > 0 Then
tb26.Value = Format(tb25.Value * Val(tb21.Value) / 100, "€#,##0.00")
Else
tb26.Value = Format(0, "€#,##0.00")
End If
' tb27
tb27.Value = Format(tb25.Value + tb26.Value, "€#,##0.00")
End Sub
Thanks in advance
JT