我有下面的代码,用于操作旋转按钮。当单元格“ D12”为空白并且用户单击向上按钮时,单元格中的值以2而不是1开头。有人知道我缺少什么吗?
Private Sub SpinButton1_Change()
Range("D12").Value = SpinButton1.Value
SpinButton1.Max = 100
SpinButton1.Min = 1
SpinButton1.SmallChange = 1
End Sub
答案 0 :(得分:1)
SpinButton1.Value
是因为缺少一个更好的词,在其他地方“隐藏”。当D12
为空时,它不知道重置为1-您应该让它知道要重置:
Private Sub SpinButton1_Change()
If Range("D12").Value = "" Then SpinButton1.Value = 1
Range("D12").Value = SpinButton1.Value
SpinButton1.Max = 100
SpinButton1.Min = 1
SpinButton1.SmallChange = 1
End Sub