Macro: Find certain criteria then delete everything below

Slowy

New Member
Joined
Aug 8, 2011
Messages
11
i have a report that creates many duplicate names. am using the Subtotals function so i can make the sheet only show 1 name.
i then have "Grand Count"

what i would like the macro do to is to
Find Grand count and then delete everything from Grand count to the end of the sheet

Grand count is ALWAYS in column A, but NOT always in the same row

thank you
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
sorry, i will be using the macro to do everything from beginning to end. i will be inserting the 'find and delete' portion into the macro
 
Upvote 0
See if you can work this in to your code
Code:
With ActiveSheet
  Set Rng = Columns("A")
Set rFound = Rng.Find(What:="Grand Count", LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False)
  'check if it was found:
  If Not rFound Is Nothing Then   'if it isn't nothing then it's something ie it was found!
    'now use rFound to start your process:
    rFound.Offset(1).Select
    Range(Selection, SpecialCells(xlCellTypeLastCell)).Select
    Selection.Delete Shift:=xlUp
    End If
End With
 
Upvote 0
Range(Selection, SpecialCells(xlCellTypeLastCell)).Select

i'm getting a Compile Error that says 'Sub of Function not Defined and it highlights 'special cells'
 
Upvote 0
Try replacing this
Code:
Range(Selection, SpecialCells(xlCellTypeLastCell)).Select
    Selection.Delete Shift:=xlUp
[CODE]
With this
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Delete Shift:=xlToLeft
[/CODE]
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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