Delete cells up after find data

tvman5683

Board Regular
Joined
Mar 23, 2009
Messages
90
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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

tvman5683

Board Regular
Joined
Mar 23, 2009
Messages
90
There you go! That did it.
Thank You for the excellent advice and quick response.

JB
 

Watch MrExcel Video

Forum statistics

Threads
1,122,809
Messages
5,598,202
Members
414,218
Latest member
speedbit

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
Top