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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

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
94
There you go! That did it.
Thank You for the excellent advice and quick response.

JB
 

Forum statistics

Threads
1,172,203
Messages
5,879,663
Members
433,450
Latest member
angelam01

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