【发布时间】:2016-11-20 08:41:51
【问题描述】:
我有一个带有一个组合框和 2 个文本框和提交按钮的小用户表单。
按下提交按钮时,我收到对象变量未设置错误。
这是我的代码:
Private Sub CommandButton1_Click()
Dim ws As Worksheet, tbl As ListObject, row As ListRow
Set ws = Sheets("Create Account Heads")
Set tbl = ws.ListObjects(Me.TextBox2.Value)
Dim intValueToFind As String, rng As Range
Set rng = tbl.ListColumns(1).DataBodyRange
intValueToFind = LCase(Me.TextBox3.Value)
If rng <> 0 Then
For Each rng In rng
If LCase(rng.Value) = intValueToFind Then
MsgBox ("Account Head with this Name Already Exists.")
Exit Sub
End If
Next rng
Else
'Unprotect the Worksheet
ws.Unprotect Password:="google"
End if
End Sub
我在“If rng 0 Then”行中遇到错误。
请查看并建议解决此问题。
谢谢 萨尔曼
【问题讨论】:
-
缩进你的代码,你有
If rng <> 0 Then和Else,你的End If在哪里? -
在下面试试我的代码,让我知道它是否可以解决您的错误
-
感谢它的工作...