A
Ayo
I have the following snipet of code. What I am trying to do is delete ranges
of consecutive rows from the worksheet. The problem is that there are gaps
between these rows of about 12 rows of other data that needs to be left
alone.
What I am trying to find out is, is there a way to reset the starting cell
in "For Each c1 In ws.Range("A4:A" & ClastRow).Cells each time I delete the
needed rows? I tried "For Each c1 In ws.Range("A" & stratingRow & ":A" &
ClastRow).Cells, but that didn't seem to work exactly as i hoped.
Any help will be greatly appreaciated.
For Each ws In Worksheets
If Mid(ws.Name, 1, 2) = "B0" Then
ws.Select
ClastRow = ActiveSheet.UsedRange.Rows.Count
currentRow = 4
startingRow = 4
For Each c1 In ws.Range("A4:A" & ClastRow).Cells
c1.Select
If Left(c1, 2) = "NY" Or Left(c1, 2) = "07" Or Left(c1, 2) =
"55" Then
currentRow = currentRow + 1
ElseIf c1 <> "" And c1 = "TOTAL" Then
EndingRow = currentRow - 1
ws.Rows(startingRow & ":" & EndingRow).Select
Selection.ClearContents
ws.Rows(startingRow & ":" & EndingRow - 1).Select
Selection.Delete Shift:=xlUp
currentRow = startingRow + 12
startingRow = currentRow
Else
End If
Next c1
End If
Next ws
of consecutive rows from the worksheet. The problem is that there are gaps
between these rows of about 12 rows of other data that needs to be left
alone.
What I am trying to find out is, is there a way to reset the starting cell
in "For Each c1 In ws.Range("A4:A" & ClastRow).Cells each time I delete the
needed rows? I tried "For Each c1 In ws.Range("A" & stratingRow & ":A" &
ClastRow).Cells, but that didn't seem to work exactly as i hoped.
Any help will be greatly appreaciated.
For Each ws In Worksheets
If Mid(ws.Name, 1, 2) = "B0" Then
ws.Select
ClastRow = ActiveSheet.UsedRange.Rows.Count
currentRow = 4
startingRow = 4
For Each c1 In ws.Range("A4:A" & ClastRow).Cells
c1.Select
If Left(c1, 2) = "NY" Or Left(c1, 2) = "07" Or Left(c1, 2) =
"55" Then
currentRow = currentRow + 1
ElseIf c1 <> "" And c1 = "TOTAL" Then
EndingRow = currentRow - 1
ws.Rows(startingRow & ":" & EndingRow).Select
Selection.ClearContents
ws.Rows(startingRow & ":" & EndingRow - 1).Select
Selection.Delete Shift:=xlUp
currentRow = startingRow + 12
startingRow = currentRow
Else
End If
Next c1
End If
Next ws