Need a vba for highlight row contain specific word until a row contain another specific word

oniototo

New Member
Joined
May 10, 2022
Messages
11
Office Version
  1. 2021
Platform
  1. Windows
123123.png

need help with vba find cell contain "NCAG" and highlight row until the cell contain "Total Sales For" then delete the row that highlighted
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is it necessary to highlight the rows or do you simply want to delete the rows?
 
Upvote 0
Is it necessary to highlight the rows or do you simply want to delete the rows?
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.
 
Upvote 0
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
 
Upvote 0
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
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.
 
Upvote 0
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?
 
Upvote 0
.. so, did you try the code that I suggested for that
123123.png

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.
 
Upvote 0
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.
The importance of representative sample data! ;)
Try this one then.

VBA Code:
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
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top