R
Robert
Hi everyone,
I'm trying to figure out how to delete an rows that
don't contain data that I want to keep. I wrote the
following macro but something is preventing me from
deleting the row... no errors occur and I don't know why
the selected rows are not being deleted. Does someone
know why this is happening?
Private Sub CommandButton1_Click()
Dim s(3) As String
Dim sLen(3) As Long
Dim i As Integer
Dim count As Integer
Dim ToBeDele() As String
s(0) = "...a"
s(1) = "...b
s(2) = " JOURNAL"
s(3) = "...c"
For i = 0 To 3 Step 1
sLen(i) = Len(s(i))
Next i
Sheets("GL20990 (2)").Activate
count = 1
For Each c In Worksheets("GL20990 (2)").Range("A1:A17")
b = False
For i = 0 To 3 Step 1
If Left(CStr(c.Value), sLen(i)) = s(i) Then
b = True
Exit For
End If
Next i
If Not b Then
If count = 1 Then
l = 0
Else: l = UBound(ToBeDele) + 1
End If
ReDim Preserve ToBeDele(l)
ToBeDele(l) = "A" & CStr(count)
End If
count = count + 1
Next c
'HERE IS MY PROBLEM! Why can't I delete the row?
For i = UBound(ToBeDele) To 0 Step -1
Set c = Range(CStr(ToBeDele(i)))
c.EntireRow.Delete
Next i
End Sub
I'm trying to figure out how to delete an rows that
don't contain data that I want to keep. I wrote the
following macro but something is preventing me from
deleting the row... no errors occur and I don't know why
the selected rows are not being deleted. Does someone
know why this is happening?
Private Sub CommandButton1_Click()
Dim s(3) As String
Dim sLen(3) As Long
Dim i As Integer
Dim count As Integer
Dim ToBeDele() As String
s(0) = "...a"
s(1) = "...b
s(2) = " JOURNAL"
s(3) = "...c"
For i = 0 To 3 Step 1
sLen(i) = Len(s(i))
Next i
Sheets("GL20990 (2)").Activate
count = 1
For Each c In Worksheets("GL20990 (2)").Range("A1:A17")
b = False
For i = 0 To 3 Step 1
If Left(CStr(c.Value), sLen(i)) = s(i) Then
b = True
Exit For
End If
Next i
If Not b Then
If count = 1 Then
l = 0
Else: l = UBound(ToBeDele) + 1
End If
ReDim Preserve ToBeDele(l)
ToBeDele(l) = "A" & CStr(count)
End If
count = count + 1
Next c
'HERE IS MY PROBLEM! Why can't I delete the row?
For i = UBound(ToBeDele) To 0 Step -1
Set c = Range(CStr(ToBeDele(i)))
c.EntireRow.Delete
Next i
End Sub