I have a small userform with one combo box and 2 text boxes and submit button.
While pressing the submit button, i am getting the object variable not set error.
Here is my code:
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
i am getting the error in "If rng <> 0 Then" line.
Kindly review and advise to overcome this issue.
Thanks Salman
If rng <> 0 Then
andElse
, where is yourEnd If
? – Shai Rado