VBA Textbox CDbl not working with Dots. 2.5 = 25

Weeble

Board Regular
Joined
Nov 30, 2016
Messages
95
Office Version
  1. 365
Code:
Dim emptyRow As Long

Worksheets("Tider").Activate


'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1


'Transfer information
Cells(emptyRow, 1).Value = CDbl(DateText.Value)
Cells(emptyRow, 6).Value = CDbl(UserText.Value)
Cells(emptyRow, 7).Value = CDbl(P10Text.Value)

If a user Enter 2.5 instead of 2,5 ( dot instead of comma ) When I transfer the data to my sheet 2.5 becomes 25.
Is there any way to change my current code in an easy way so that VBA converts it to a comma if user has input a dot?
I searched for many different solutions. But none that I could implement easy into my code.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello,
2 ways :

1st : using Val instead of CDbl
2nd : using a personal function and Replace()

Code:
Option Explicit

Sub Demo()
Dim n As String
    n = "2.5"
    Debug.Print Val(n)  'first way
    n = Replace(n, CommaInsteadOfPoint, Application.DecimalSeparator) 'second way
    Debug.Print CDbl(n)
End Sub


Private Function CommaInsteadOfPoint() As String
    CommaInsteadOfPoint = IIf(Application.DecimalSeparator = ".", ",", ".")
End Function
 
Upvote 0
Thank you for the tips!
Before I got try them out I used this
Code:
Cells(emptyRow, 7).Value = CDbl(Replace(P10Text.Value, ".", ","))
Could this have any negative effect on the code?
Or does it work?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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