Find specific text, select rows upward (- the selected cell) then delete

VBAWannabee2

New Member
Joined
Feb 23, 2022
Messages
28
Office Version
  1. 2010
Platform
  1. Windows
Good day!

Hi, asking for your little help on this one.
After finding(selecting) the value of "Proj" on the active sheet, I want to delete all rows above it except the row where the "Proj" exist.
The code for it was the only one I'm missing / having trouble to.

Sub Process1()

ActiveSheet.Select
cells.Sort Key1:=Columns("A"), key2:=Columns("B")

cells.Find(What:="Proj", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select

---missing---
selection.Delete shift:=xlUp

End Sub

Thank you in advance!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
for the missing part:

Code:
range(cells(1,"A"), selection.offset(-1,0)).entirerow.select
 
Upvote 0
Solution
Perhaps:
VBA Code:
Sub Process1()
    Cells.Sort Key1:=Columns("A"), Key2:=Columns("B")
    Rows("1:" & Cells.Find(What:="Proj").Row - 1).Delete
End Sub
 
Upvote 0
Perhaps:
VBA Code:
Sub Process1()
    Cells.Sort Key1:=Columns("A"), Key2:=Columns("B")
    Rows("1:" & Cells.Find(What:="Proj").Row - 1).Delete
End Sub
Works like magic too Sir! would love to mark this as a solution too but sadly it can't (Works well though :) ) but thank you and cheers!

I'mma study this code of yours but am I correct? Does "1:" refers to 1st row of the sheet? then "Cells.Find(What:="Proj").Row-1) refers to the row above the cell where "Proj" belongs?
 
Upvote 0
I'mma study this code of yours but am I correct? Does "1:" refers to 1st row of the sheet? then "Cells.Find(What:="Proj").Row-1) refers to the row above the cell where "Proj" belongs?
No worries and that is correct
 
Upvote 0
VBA Code:
Sub Process1()
    Cells.Sort Key1:=Columns("A"), Key2:=Columns("B")
    Rows(Cells.Find(What:="Proj").Row & ":" & Rows.Count).Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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