Numeric top-down control in vba

Is there a built-in numerical updown control in vba or do we need to create such a control?

If there is such control, then what events can we use.

Offer Pls.

+6
source share
1 answer

You can use the SpinButton1 control to do this.

Snapshot

enter image description here

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 
+16
source

Source: https://habr.com/ru/post/918544/


All Articles