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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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