使用组合框 select 和 excel 用户表单中的选项按钮
Using a Combobox to select and option button in excel userform
我是 vba 的新手,在使用用户表单时遇到了一些问题。
我正在尝试使用它,以便当组合框中的 selection 包含某个字母时,选项按钮是 selected.
我尝试使用的代码是:-
Private Sub ComboBox1_Change()
If ComboBox1.Value = "*C*" Then
OptionButton3.Value = True
End If
If ComboBox1.Value = "FR 850 C BLUE" Then
TextBox2.Value = "BLUE"
End If
If ComboBox1.Value = "FR 850 C WHITE" Then
TextBox2.Value = "WHITE"
End If
End Sub
但是,TextBox2
仅在以下情况下可见:
Private Sub OptionButton3_Click()
TextBox2.Visible = True
With Me.TextBox2
.Value = "Colour here"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
当包含 "C" 的选项被 selected 时,请参阅用户表单的 this printscreen(见下文)- OptionButton3
保持未selected。
我还尝试编写代码,以便当 "FR 850 C BLUE" 被 select 编辑时,TextBox2
将显示 "BLUE"。我怀疑一旦我找到对第一部分的修复,这会更好地工作,但是,如 this printscreen(见下文)所示,如果你在 "FR 850 C BLUE" 之后 select OptionButton3
Combobox1
,TextBox2
没有显示 "BLUE",正如我希望的那样。
有人能帮忙吗?我怀疑我错过了什么地方...
Any/all欢迎评论!
您是在说:
If ComboBox1.Value = "*C*" Then
这意味着,如果 ComboBox1.Value
等于 "*C*"
做某事。
要检查值是否部分匹配,请使用 Like
:
If ComboBox1.Value Like "*C*" Then
我是 vba 的新手,在使用用户表单时遇到了一些问题。 我正在尝试使用它,以便当组合框中的 selection 包含某个字母时,选项按钮是 selected.
我尝试使用的代码是:-
Private Sub ComboBox1_Change()
If ComboBox1.Value = "*C*" Then
OptionButton3.Value = True
End If
If ComboBox1.Value = "FR 850 C BLUE" Then
TextBox2.Value = "BLUE"
End If
If ComboBox1.Value = "FR 850 C WHITE" Then
TextBox2.Value = "WHITE"
End If
End Sub
但是,TextBox2
仅在以下情况下可见:
Private Sub OptionButton3_Click()
TextBox2.Visible = True
With Me.TextBox2
.Value = "Colour here"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
当包含 "C" 的选项被 selected 时,请参阅用户表单的 this printscreen(见下文)- OptionButton3
保持未selected。
我还尝试编写代码,以便当 "FR 850 C BLUE" 被 select 编辑时,TextBox2
将显示 "BLUE"。我怀疑一旦我找到对第一部分的修复,这会更好地工作,但是,如 this printscreen(见下文)所示,如果你在 "FR 850 C BLUE" 之后 select OptionButton3
Combobox1
,TextBox2
没有显示 "BLUE",正如我希望的那样。
有人能帮忙吗?我怀疑我错过了什么地方...
Any/all欢迎评论!
您是在说:
If ComboBox1.Value = "*C*" Then
这意味着,如果 ComboBox1.Value
等于 "*C*"
做某事。
要检查值是否部分匹配,请使用 Like
:
If ComboBox1.Value Like "*C*" Then