i want a function that can find a specific word like "NCAB" or "NCAG" and highlight the row contain the word i search until the the row that contain word "Total Sales For" below the word i search then clear it or delete the row.Is it necessary to highlight the rows or do you simply want to delete the rows?
Sub Del_Rows()
Columns("A").Find(What:="NCAG", LookIn:=xlValues, LookAt:=xlWhole).CurrentRegion.EntireRow.Delete
End Sub
i'm sorry if i not clear enough. maybe i doesn't need to highlight, i just need to delete it until the row contain 1st "Total Sales For" below it.I'm not sure you have really clarified @mumps question. If you highlight the rows and then delete the rows, what was the point of highlighting them?
Try this with a copy of your workbook.
VBA Code:Sub Del_Rows() Columns("A").Find(What:="NCAG", LookIn:=xlValues, LookAt:=xlWhole).CurrentRegion.EntireRow.Delete End Sub
.. so, did you try the code that I suggested for that?i'm sorry if i not clear enough. maybe i doesn't need to highlight, i just need to delete it until the row contain 1st "Total Sales For" below it.
.. so, did you try the code that I suggested for that
The importance of representative sample data!the 1st pic i posted is only an example. actually the condition may look like this. it's a report generated by some software to excel. using the code u suggested will not work.
Sub Del_Rows_v2()
Dim rStart As Range, rEnd As Range
Set rStart = Columns("A").Find(What:="NCAG", LookIn:=xlValues, LookAt:=xlWhole)
Set rEnd = Columns("A").Find(What:="Total*", After:=rStart, LookIn:=xlValues, LookAt:=xlWhole)
Range(rStart, rEnd).EntireRow.Delete
End Sub