2016-08-23 44 views
1

我是vba的新手,並且在用戶表單中遇到了一些麻煩。 我想擁有它,以便當組合框中的選擇包含某個字母時,選擇一個選項按鈕。使用組合框選擇和選項按鈕在excel用戶表單

我曾嘗試使用的代碼是: -

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 

參見this printscreen(見下文)的用戶窗體的含有一個選項時選擇「C」 - OptionButton3保持未選中狀態。

printscreen

另外我試圖代碼,以便當選擇 「FR 850℃BLUE」,TextBox2將顯示 「BLUE」。我懷疑,一旦我找到第一部分的修復,這將工作得更好,但是,如this printscreen(見下文)所示,如果您在Combobox1的「FR 850 C BLUE」之後選擇OptionButton3TextBox2不顯示「BLUE」我希望它。

printscreen

誰能幫助?我懷疑我錯過了什麼地方...

任何/所有評論歡迎!

回答

1

您指出:

If ComboBox1.Value = "*C*" Then 

這意味着,如果ComboBox1.Value等於"*C*"做一些事情。
要檢查值部分匹配您使用Like

If ComboBox1.Value Like "*C*" Then 
+0

非常感謝,認爲整理吧! :) – StanB

相關問題