Excel 2000 VBA Deleting Rows when certain text in rows exists

  • Thread starter Thread starter scain2004
  • Start date Start date
S

scain2004

When data is inserted into a worksheet from a text file, it inserts th
page header into the worksheet as well. This text file is severa
pages worth of data, but every page has a page header. Unfortunately
the headers don't show up on the same rows on every sheet imported.
need to be able to these delete rows where the text in in the firs
column of the first row to be deleted is "Sunl" and until the text i
the second column of the last row to be deleted is "Job". This need
to be done automatically after the data is imported. I've got i
imported automatically, just need to delete the appropriate row
involved.

Any ideas?

Thanks,
Stev
 
I hope i understand your problem correctly

Not tested

Deletes all rows in between the words "Sunl" (column a) & "Job
(column b)


for loop needs to step backwards due to when rows are deleted th
remaining rows are re numbered

eg delete row 5 row 6 becomes new row 5.

if macro steped forward then the new row 5 would not be checked


Sub DelRows()
Dim sRow As Long
Dim lRow As Long

Dim i As Long

For i = Range("a65536").End(xlUp).Row To 1 Step -1
If Cells(i, "b") = "Job" Then
lRow = i
ElseIf Cells(i, "a") = "Sunl" Then
sRow = i
End If
If sRow > 0 And lRow > 0 Then
Rows(sRow & ":" & lRow).Delete
sRow = 0
lRow = 0
End If
End Su
 
Back
Top