Sum up currency text boxes in userform decimal problem

João Sequeira

Board Regular
Joined
Jun 29, 2015
Messages
93
Hi,

I have a userform where you enter currency values into two text boxes (tVALUE & tVAT).
Upon adding values it should update a label (lTOTAL) with the sum of both text boxes.

The code works but I can't get decimal values to show up in lTOTAL, it always shows "value,00 €" and I can't understand why.

Here's my code:
Code:
Private Sub tVALUE_AfterUpdate()


If Not IsNumeric(tVALUE) And Len(tVALUE) > 0 Then
    MsgBox "Only currency values are allowed."
    tVALUE = ""
    tVAT = Format(tVAT, Number)
    lTOTAL = Val(tVALUE) + Val(tVAT)
    lTOTAL = Format(lTOTAL, "CURRENCY")
    tVAT = Format(tVAT, "CURRENCY")
    Exit Sub
        Else
        tVAT = Format(tVAT, Number)
        tVALUE = Format(tVALUE, Number)
        lTOTAL = Val(tVALUE) + Val(tVAT)
        lTOTAL = Format(lTOTAL, "CURRENCY")
        tVALUE = Format(tVALUE, "CURRENCY")
        tVAT = Format(tVAT, "CURRENCY")
End If


End Sub


Private Sub tVAT_AfterUpdate()


If Not IsNumeric(tVAT) And Len(tVAT) > 0 Then
    MsgBox "Only currency values are allowed."
    tVAT = ""
    tVALUE = Format(tVALUE, Number)
    lTOTAL = Val(tVALUE) + Val(tVAT)
    lTOTAL = Format(lTOTAL, "CURRENCY")
    tVALUE = Format(tVALUE, "CURRENCY")
    Exit Sub
        Else
        tVALUE = Format(tVALUE, Number)
        tVAT = Format(tVAT, Number)
        lTOTAL = Val(tVALUE) + Val(tVAT)
        lTOTAL = Format(lTOTAL, "CURRENCY")
        tVAT = Format(tVAT, "CURRENCY")
        tVALUE = Format(tVALUE, "CURRENCY")


End If

Thanks,
João
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Found answer in another post.

My problem is that my currency settings are "," for decimal separator and Val function doesn't recognize it as separator, it only recognizes ".".

So here's the code:

Code:
Private Sub tVALUE_AfterUpdate()

If Not IsNumeric(tVALUE) And Len(tVALUE) > 0 Then
    MsgBox "Only currency values are allowed."
    tVALUE = ""
    lTOTAL = Val(Replace(tVALUE, ",", ".")) + Val(Replace(tVAT, ",", "."))
    Exit Sub
        Else
        tVALUE = Format(tVALUE, "CURRENCY")
        lTOTAL = Val(Replace(tVALUE, ",", ".")) + Val(Replace(tVAT, ",", "."))
        lTOTAL = Format(lTOTAL, "CURRENCY")
End If


End Sub
Private Sub tVAT_AfterUpdate()


If Not IsNumeric(tVAT) And Len(tVAT) > 0 Then
       MsgBox "Only currency values are allowed."
    tVAT = ""
    lTOTAL = Val(Replace(tVALUE, ",", ".")) + Val(Replace(tVAT, ",", "."))
    Exit Sub
        Else
        tVAT = Format(tVAT, "CURRENCY")
        lTOTAL = Val(Replace(tVALUE, ",", ".")) + Val(Replace(tVAT, ",", "."))
        lTOTAL = Format(lTOTAL, "CURRENCY")
End If


End Sub

Thanks,
João
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top