SpinButton with padded numbers

teachman

Active Member
Joined
Aug 31, 2011
Messages
321
Hello,

I have a numeric text field that allows 000 to 999. I would like to use a SpinButton control to allow users to enter the number. However, if the number is less than 100 it needs to be padded on the left with the zero character. i.e. 5 needs to be 005, 51 needs to be 051. The SpinButton control does not seem to allow for this. Is there any other option out there that I might be able to use?

Thanks for your help.

George
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] UserForm_Initialize()
    TextBox1.Value = "000"
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] SpinButton1_SpinUp()
    [color=darkblue]If[/color] TextBox1.Value < 999 [color=darkblue]Then[/color]
        TextBox1.Value = Format(TextBox1.Value + 1, "000")
    [color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] SpinButton1_SpinDown()
    [color=darkblue]If[/color] TextBox1.Value > 0 [color=darkblue]Then[/color]
        TextBox1.Value = Format(TextBox1.Value - 1, "000")
    End [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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