1
# 更新代碼設置驗證
Function condition(ByRef objCmb As ComboBox)
If objCmb.Value ="" And objCmb.Value = "g" Then
Call MsgBox("gg", vbOKOnly, "error")
End If
End Function
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
condition (ComboBox1)
End Sub
'other codes for reference:
Private Sub CommandButton1_Click()
Dim lastrow As Integer
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To 3
For j = 1 To 5
With Me.Controls("ComboBox" & (i - 1) * 5 + j)
If .Text <> "" Then
Cells(lastrow + i, j) = .Text
Else
Exit Sub
End If
End With
Next j
Next i
End Sub
我在VBA用戶面板50個組合和文本框。由於在每個組合框或文本框中設置約束條件太麻煩,我想要一個函數應用於每個組合框和文本框。
對於上面的代碼,它顯示了cant find object
錯誤
如何解決?
順便說一句,如何設置功能語句的文本框? 是Function condition2(ByRef objCmb As textbox)...
你在你的函數接收'objCmb'。使用它,而不是'ComboBox'。 –
Ken在說什麼,是用If if objCmb.Value <>「」和objCmb.Value =「g」替換你的'If ComboBox.Value <>「」And ComboBox.Value =「g」Then'然後' –
i嘗試過,仍然無法找到條件(ComboBox1)中的對象錯誤' – Monchhichi