Delete cells up after find data

tvman5683

Board Regular
Joined
Mar 23, 2009
Messages
94
I use this code to find a cell that contains the text"Data:" then delete everything that follows to the Last Cell.
I would like to change this in order to delete everything preceding this cell or in other words to the First cell.
I'm thinking it's two steps after finding the cell.
Active Cell move up 1
Then Select Active cell to first cell then delete.
any suggestions would be appreciated


HTML:
Sub FindData()
   With Range("B:K")
   Cells.Find(what:="Data:", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
    .Activate
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.EntireRow.Delete
  End With
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Code:
Sub FindData()
Dim Found As Range
   Set Found = Range("B:K").Find(what:="Data:", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If Not Found Is Nothing Then Rows(1 & ":" & Found.Row).Delete
End Sub
 
Upvote 0
Try

Rich (BB code):
Sub FindData()
Dim Found As Range
   Set Found = Range("B:K").Find(what:="Data:", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If Not Found Is Nothing Then Rows(1 & ":" & Found.Row - 1).Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

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