Excel – 根据单元格内容设置Userformcheckbox的值

我正在开发一个用户表单,其中的一个部分包含三个指向世界不同地方的checkbox。 根据这些组合,在文本C9中input一个文本值。

我想要checkbox反映当用户返回到用户窗体时已经在单元格中的内容。 我已经能够为用户窗体(选项button,文本框,combobox)中的每个其他项目执行此操作,但是我的checkbox根本没有响应,只要在用户窗体出现时就取消选中,而不考虑C9的值。

以下代码位于userform_intialize模块中。 有任何想法吗?

If wsM.Range("C9").Value = "EU-5" Then NABox.Value = False And EUBox.Value = True And RoWBox.Value = False ElseIf wsM.Range("C9").Value = "EU-5 & RoW" Then NABox.Value = False And EUBox.Value = True And RoWBox.Value = True ElseIf Sheets("Menu").Range("C9").Value = "NA & EU-5" Then NABox.Value = True And EUBox.Value = True And RoWBox.Value = False ElseIf wsM.Range("C9").Value = "North America" Then NABox.Value = True And EUBox.Value = False And RoWBox.Value = False ElseIf wsM.Range("C9").Value = "NA & RoW" Then NABox.Value = True And EUBox.Value = False And RoWBox.Value = True ElseIf wsM.Range("C9").Value = "Rest of World" Then NABox.Value = False And EUBox.Value = False And RoWBox.Value = True Else: NABox.Value = False And EUBox.Value = False And RoWBox.Value = False End If 

谢谢你的帮助。

Me. 关键字在checkbox名称前面。
也可以更好地使用SELECT CASE语句而不是ElseIf

NABox.Value = False And EUBox.Value = True And RoWBox.Value = False需要三个单独的命令。 可以在单独的行上,也可以使用:在下面的代码中是两个例子)。

 Private Sub UserForm_Initialize() With Me Select Case wsm.Range("C9").Value Case "EU-5" NABox.Value = False EUBox.Value = True RoWBox.Value = False Case "EU-5 & RoW" NABox.Value = False : EUBox.Value = True RoWBox.Value = False Case "NA & EU-5" Case Else End Select End With End Sub 

编辑 – 我不认为你需要显式地声明虚假的checkbox – 默认情况下,当窗体打开时它们是False。