【发布时间】:2021-01-12 08:58:32
【问题描述】:
【问题讨论】:
【问题讨论】:
将此添加到您的用户表单模块中:
Private Sub UserForm_Initialize()
If Sheets("Sheet1").Range("B4") = "Profit" Then Me.ProfitOption.Value = True
End Sub
几件事要改变:
-将Sheet1 更改为您的。
-将ProfitOption 更改为按钮的名称。
【讨论】:
Me.ProfitOption.Value 是Boolean 而不是String 因此应该是Me.ProfitOption.Value = True
我推荐这样的东西
Private Sub UserForm_Initialize()
Select Case Sheet1.Range("B4").Value 'evaluate the value of the cell
Case "Profit"
Me.OptionButton1.Value = True
Case "Loss"
Me.OptionButton2.Value = True
Case Else 'if it is none of the above then go into undefined state
Me.OptionButton1.Value = Null
Me.OptionButton2.Value = Null
End Select
End Sub
请注意,如果您更改用户表单中的选项,这不会更改单元格值。因此,您需要使用Private Sub OptionButton1_Change() 事件或“保存”按钮将更改的状态写回。
【讨论】: