在标签上显示SpinButton的选定值

我需要用SpinButton创build一个UserForm。 用户select一个值,完成后点击OK(将所选值传递给另一个过程)。

这是它的样子:

在这里输入图像说明

现在, 我如何在标签上的SpinButton中显示选定的值,或者显示用户select了哪个值?

只需使用SpinButton1_Change事件。 当您单击旋钮上/下箭头时,这将更新标签实时。

在用户表单代码区域,只需粘贴此代码即可

 Private Sub SpinButton1_Change() Label1.Caption = SpinButton1.Value End Sub 

您需要在UserForm_Initialize定义SpinButton,然后在SpinButton_Change添加一行以更新Label:

 Private Sub UserForm_Initialize() With SpinButton1 .Min = 0 'Min Value .Max = 100 'Max Value 'Specify the value of the change when the spin button is clicked .SmallChange = 5 '(Default = 1) End With End Sub Private Sub SpinButton1_Change() Label1.Caption = SpinButton1.Value End Sub