I have written the following Function to scroll through each row in a column searching for a particular value. If that value is found then the row is left alone. If the row contains anything else then delete the entire row.
Function DeleteReferral2(TargetSheet As Worksheet, strFindMe As String)
Dim k As Long
With TargetSheet
For k = .Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
If .Cells(l, "A").Value = strFindMe Then
Else
.Cells(l, "A").EntireRow.Delete
Next k
End With
End Function
I have tried to call the Function in the following code. When I do, I get a "Compile error: Expected: =" as soon as I even type the code. I have highlighted the code in question in red.
Private Sub CommandButton1_Click()
Dim TargetSheet As Worksheet
Dim strFind As String
Dim Ctrl1 As Control
Dim Ctrl2 As Control
Call FillDateRange
For Each Ctrl1 In RefTrack.Frame1.Controls
If TypeName(Ctrl1) = "OptionButton" Then
If Ctrl1.Value = True Then
Set strFind = Ctrl1.Caption
Else
End If
End If
Next Ctrl1
If Me.OptionButton10.Value = True Then
Call CopySheets
For Each Ctrl2 In RefTrack.Frame2.Controls
If TypeName(Ctrl2) = "CheckBox" Then
If Ctrl2.Value = True Then
If Ctrl2.Caption = "Information/Service Only" Then
Set TargetSheet = Sheets("Information Only")
DeleteReferral2(TargetSheet, strFind)
Else
End If
Else
End If
End If
Next Ctrl2
Can anyone shed some light on what the issue is and how to possibly solve it?
Thank you,
Brian
Bookmarks