How to replace other numbers?

Hi Experts,
can you help with macro that will replace the numbers? I control TextBox1 into which a user types a number between 100 and 9999999, I need to if the user writes three-digit number, the last digit replaced by zero. If you write a four-digit number, the last two digits were replaced by zeros. If you write a five-digit number, the last three digits replaced with zeros. If you write six-digit number, last four digits were replaced by zeros.
 Macro should start by clicking the CommandButton1.
 See attached sample.
 Many thanks in advance for any help. Remove-numbers.ppt
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this
Option Explicit

Private Sub CommandButton1_Click()
    Dim strNumbers As String
    Dim l As Integer
    strNumbers = CStr(TextBox1.Text)
    l = Len(strNumbers)
    TextBox1.Text = Left$(strNumbers, 2) & String(l - 2, "0")
End Sub

Open in new window

Assuming this is Textbox1

Private Sub TextBox1_Change()
Dim L As Long
If Not IsNumeric(Me.TextBox1.Text) Then Me.TextBox1.Text = ""
L = Len(Me.TextBox1.Text)
If L > 2 Then Me.TextBox1.Text = Left(Me.TextBox1.Text, 2) & String(L - 2, "0")
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Note this does not require a click on the button but if you need that just transfer the code.
Thomas_MeyerAuthor Commented:
Perfect, thank you for all the help.
Best regards,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.