I'm reading in values from an Excel sheet and have the user checking those numbers/text and hitting save again if they are correct. It works well for any text and numbers, except for my discount being of double type.
Private Sub UserForm_Initialize()
' filling form
TextHN.Text = Range("D3")
'...
' original: TextDP.Text = Range("D7") - but wouldn't read in 12.5
' therefore tried below as well
Dim new_value As Double
If IsNumeric(Range("D7").Value) Then
new_value = CDbl(Range("D7").Value)
MsgBox new_value # displays 12.5
Else
new_value = 1
End If
TextDP.Text = CStr(CDbl(new_value))
MsgBox TextDP.Text # displays 12
I read several articles (Convert TextBox.Value to Double into VBA (Excel 2013) & https://www.mrexcel.com/board/threads/textbox-value-to-double.1066876/), but nothing helped. How do I need to change my code to display my discount in TextDP? (I can read it out as double into Excel file fine)
Update with screenshots:
I'm surprised that it displays it for hospital name and abbreviation correctly (and saves it accordingly), but not for discount percentage and expiry length...
new_value = CDbl(Range("D7").Value)
. It displays the proper content. Why are you then trying to make it a double again and then convert it to a string withTextDP.Text = CStr(CDbl(new_value))
when it's already a double? You don't need the second call toCDbl
before you useCStr
- just useCStr(new_value)
.=ISNUMBER(D7)
. Why does it have two digits after the dot? What is the number format of D7? What is the value of the MaxLength property of TextDP?