Format a TextBox on a Userform to 2 decimal places

Zaurb

New Member
Joined
Mar 6, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hi!

Am having a similar issue as described in this post.

My code is as follows:

VBA Code:
Private Sub cmdCalculate_Click()
If IsNumeric(Me.txt_odds.value) Then
    Me.txt_odds = Format(txt_odds.value, "0" & Application.DecimalSeparator & "00")
End If
Me.txt_Minimum = Format(100 / txt_odds.value, "0" & Application.DecimalSeparator & "00%")
End Sub

However, I get strange results. For example, if I input 1.5 in the first textbox and expect to see it as 1.50 after clicking calculate button, I see instead 15.00. However, if i write 2 it display correctly as 2,00.
Can you please help me?

Thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello Zaurub,
try to do something like this...
VBA Code:
Private Sub cmdCalculate_Click()
    
    Dim vTR As String
    
    vTR = Replace(Me.txt_odds.Value, ".", ",")
    If IsNumeric(Me.txt_odds.Value) Then
         Me.txt_Minimum = Format(100 / vTR, "0.00") & "%"
    End If
   
End Sub
 
Upvote 0
Hello Zaurub,
try to do something like this...
VBA Code:
Private Sub cmdCalculate_Click()
   
    Dim vTR As String
   
    vTR = Replace(Me.txt_odds.Value, ".", ",")
    If IsNumeric(Me.txt_odds.Value) Then
         Me.txt_Minimum = Format(100 / vTR, "0.00") & "%"
    End If
  
End Sub
Thank you very much!
Results calculating correctly. But i still don't get 2 decimal points. Is there any fix for that? Thanks again!
 
Upvote 0
Thank you very much!
Results calculating correctly. But i still don't get 2 decimal points. Is there any fix for that? Thanks again!
2 decimal points in txt_odds textbox
 
Upvote 0
resolved making a little modification as follows:
VBA Code:
Dim vTR As String

    vTR = Replace(Me.txt_odds.value, ".", ",")
    Me.txt_odds = Format(vTR, "0.00")
    If IsNumeric(Me.txt_odds.value) Then
         Me.txt_Minimum = Format(100 / vTR, "0.00") & "%"
    End If
 
Upvote 0
Yes, now is correct. I'm glad that you were capable to understand the point.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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