You can use the SpinButton1
control to do this.
Snapshot
CODE
You can set the minimum and maximum values โโof SpinButton1
at design time or at run time, as shown below.
Private Sub UserForm_Initialize() SpinButton1.Min = 0 SpinButton1.Max = 100 End Sub Private Sub SpinButton1_Change() TextBox1.Text = SpinButton1.Value End Sub
Followup
If you want to increase or decrease the value of the text field based on what the user enters into the text field, use this. It also makes the text box the text box "Only number", which just executes your other request;)
Private Sub SpinButton1_SpinDown() TextBox1.Text = Val(TextBox1.Text) - 1 End Sub Private Sub SpinButton1_SpinUp() TextBox1.Text = Val(TextBox1.Text) + 1 End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case vbKey0 To vbKey9, 8 Case Else KeyAscii = 0 Beep End Select End Sub
source share