View Full Version : textbox format
av8tordude
03-06-2017, 04:44 AM
I have the code that I like to be able to to put more zeros (i.e. $0.0000), but I'm running out of answers. Can some assist. Thanks
Dim v As String
Select Case Len(tbSPrice)
Case 1
tbSPrice = Format(tbSPrice, "00\.00")
Case Is > 1
v = Replace(tbSPrice, "$", "")
v = Replace(v, ".", "")
tbSPrice = Format(CCur(v) / 100, "$#,##0.00")
Case Else
End Select
tbSPrice = Format(v / 100, "$#,###.0000")
Paul_Hossler
03-06-2017, 09:03 AM
What is an example of tbSPrice going in and what is the format you want to see coming out?
It looks like you replace the $ and . and then format it again with a $ and . but /100
Confusing to me
av8tordude
03-06-2017, 09:42 AM
its a userform textbox. The code automatically formats the numbers into currency format as I type. only problem I'm facing is when I have currency that have extra numbers (i.e. $5.8686). On another note. The code SamT offered didn't work.
extra numbers (i.e. $5.8686). On another note. The code SamT offered didn't work.
18563
Perhaps you can provide us with some Examples of the Textbox entries and what you want them to be formatted as. Your explanation is lacking too many details.
Note: All TextBox values are strings.
Perhaps
tbSPrice = Format(CDbl(v), "$#,###.0000")
Paul_Hossler
03-06-2017, 09:01 PM
I'm still not clear on the requirements, but try this
Option Explicit
Sub PH()
Dim tbSPrice As String
Dim i As Long
tbSPrice = "$5.8686"
i = InStr(tbSPrice, ".")
If i = 0 Then
tbSPrice = tbSPrice & ".00"
Else
tbSPrice = Left(tbSPrice, i) & Mid(tbSPrice & "00", i + 1, 2)
End If
MsgBox tbSPrice
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.