Difficulty with decimals and "." and ","

RossioPS

New Member
Joined
Aug 7, 2017
Messages
2
So basically my regional settings are set to European.

I have a userform that I would like to make sure that all values are passing correctly. What I mean is, when a user passes a decimal value to the form this value would be correctly calculated.

Code:
If (CDbl(Replace(txtValor, ".", ","))) <> CDbl(txtValor) Then        
        Cartao = CDbl(Replace(txtValor, ".", ","))
    Else
        Cartao = CDbl(txtValor)
    End If

I tried using this to make sure that this happens, but when I run the form and test it by putting a value in the way "125.25"
I get "type Mismatch"

If I put "125,25" it works fine.

Am I using the replace function wrong here?

Thanx for the help in advance
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi!

There's a post here with the same topic :)
This code works for me:

Code:
Dim sVal As String


sVal = Replace(txtValor, ".", ",")


'   return double if string is not empty and is numerical
If Not sVal = "" Then
    If IsNumeric(sVal) = True Then


        cartao = CDbl(sVal)
        
    End If
End If
 
Upvote 0
Hi!

There's a post here with the same topic :)
This code works for me:

Code:
Dim sVal As String


sVal = Replace(txtValor, ".", ",")


'   return double if string is not empty and is numerical
If Not sVal = "" Then
    If IsNumeric(sVal) = True Then


        cartao = CDbl(sVal)
        
    End If
End If

Thank you very much your answer work for me!

Sorry I didn't find the other topic I need to make better searchs
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,681
Members
449,048
Latest member
81jamesacct

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