Add decimal point at specific position

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to loop through a series of Textboxes on a Userform and enter a decimal point after the first 2 numbers entered;

Code:
Dim ctrl As MSForms.controlFor Each ctrl In Controls
If ctrl.Name Like "TextSTime*" Then
If Len(ctrl.Value) = 3 Then ctrl.Value = Left(ctrl.Value, 2) & "." & Right(ctrl.Value, 1)
End If
Next

I need something similar now - what I need is for it to add the decimal point before the last 2 numbers, regardless of how many are entered, (although I have limited the Textboxes to a maximum of 6 characters).

Some examples of what I'd expect to see:


Anyone?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
In that case try
Code:
[COLOR=#0000ff]Dim DisableEvents As Boolean[/COLOR]
Private Sub TextBox1_Change()
   If DisableEvents Then Exit Sub
   DisableEvents = True
   With Me.TextBox1
      If Len(.Value) > 1 Then
         If InStr(.Value, ".") > 0 Then .Value = .Value * 1000
         .Value = .Value / 100
      End If
   End With
   DisableEvents = False
End Sub
The part in blue must go at the very top of the module, before any code.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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