Delete All Rows Above Trigger

  • Thread starter Thread starter CFitz
  • Start date Start date
C

CFitz

I'm looking for a macro that will find the row that contains the word "Other"
and then delete every row above it. Unfortunately there isn't a specific
column to look in because columns are constantly being added and subtracted
from the file.

Thanks!
 
See if this works. I didn't test it.

Sub DelAllAbove()
Dim c As Range
Set c = ActiveWorkbook.ActiveSheet. _
Find("Other", LookIn:=xlValues)
If Not c Is Nothing Then
Range("A1:A" & c.Row + 1).EntireRow.Delete
End If
End Sub
 
I had a typo in the first one. Should have been a minus sign.

Sub DelAllAbove()
Dim c As Range
Set c = ActiveWorkbook.ActiveSheet. _
Find("Other", LookIn:=xlValues)
If Not c Is Nothing Then
Range("A1:A" & c.Row - 1).EntireRow.Delete
End If
End Sub
 
It didn't work. I'm getting an error that says "Object doesn't support this
property or method" and it highlights

Set c = ActiveSheet. _
Find("Other", LookIn:=xlValues)
 
Still getting the same error as above.

JLGWhiz said:
I had a typo in the first one. Should have been a minus sign.

Sub DelAllAbove()
Dim c As Range
Set c = ActiveWorkbook.ActiveSheet. _
Find("Other", LookIn:=xlValues)
If Not c Is Nothing Then
Range("A1:A" & c.Row - 1).EntireRow.Delete
End If
End Sub
 
Sub DelAllAbove()
Dim c As Range
With ActiveSheet
Set c = .Cells _
.Find("Other", LookIn:=xlValues)
If Not c Is Nothing Then
If c.Row = 1 Then
.Rows(1).Delete
Else
.Range("A1:A" & c.Row - 1).EntireRow.Delete
End If
Else
MsgBox "Other not found"
End If
End With
End Sub
 
Thanks!

Tom Ogilvy said:
Sub DelAllAbove()
Dim c As Range
With ActiveSheet
Set c = .Cells _
.Find("Other", LookIn:=xlValues)
If Not c Is Nothing Then
If c.Row = 1 Then
.Rows(1).Delete
Else
.Range("A1:A" & c.Row - 1).EntireRow.Delete
End If
Else
MsgBox "Other not found"
End If
End With
End Sub
 
Yeah, haste makes waste. Forgot the Cells. Without that it don't know where
to look. Tom caught it right off.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top