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