【发布时间】:2020-05-22 13:05:07
【问题描述】:
在我的表单中,我希望用户能够根据选项框并根据他们的输入看到颜色或动物。到目前为止我尝试过的代码对我不起作用,我认为这是因为我不明白如何正确格式化它。
我已经尝试为每种颜色的每个数字执行此操作,我尝试将数字添加为可能的值,并尝试创建一个数组。但是没有成功。
例如。
如果选择了Optionbutton A,并且textbox A 的值为1、4 或10,则textbox B 将显示为蓝色。但如果 textbox A 的值为 2、3、5 或 9,则 textbox B 将显示绿色。
示例 2。
Optionbutton B,而textbox A 的值为 1、3、4、10 或 12,则 textbox B 将显示蝴蝶。但如果 textbox A 的值为 2、5、7,则 textbox B 将显示 Caterpie。
添加了注释,我不知道表单是否可能,但如果用户要在选项框之间切换,则文本框 B 会相应更改。
Private Sub txtboxA_Change()
Dim txtboxA As String
Dim Colourarray As Variant
Blue = Array("1", "4", "10")
Me.txtboxA.MaxLength = 2
'If OptA is selected then pick colour based on textbox value
If Me.OptA.Value = True And Me.txtboxA.Value = "1" Then 'This bit seemed to work, but once I copied this for every number which needs to show green, vba got unhappy at me.
'If Me.OptA.Value = True And Me.txtboxA.Value = "1", "4", "10" Then
'If Me.optA.Value = True And (Poort = "1", "4", "10") Then
'If Me.txtboxA.Value = Colourarray And Me.optA.Value = True Then
Me.txtboxB.Value = "Blue"
End If
End Sub
【问题讨论】:
-
正确的语法是这样
Value = "1" Or Value = "4"等等。
标签: excel vba multiple-conditions