I'm not even sure if there's a solution on this one....

PETERFT73

New Member
Joined
Oct 31, 2017
Messages
12
Hi everyone,
So I've got a workbook with about 5500 rows of stats. The first column is a name and I need to delete or clear the first 3 rows each time a new name appears (the names are in alphabetical order). Some names have many more instances than others and there's no pattern to it. The most I've been able to do is find a way to insert a blank row between each name, but I can't figure how to do the deleting except to do it manually.
Any help would be greatly appreciated.
Thanks!!
Peter
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
let A1 = fred
add alan to bottom of list, sort, so A1=alan and A2 = fred

do you really want to delete rows 1,2,3 ??????????????
 
Upvote 0
Give this macro a try...
Code:
Sub ClearFirstThreeNewNames()
  Dim R As Long, Cell As Range
  For R = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    If Cells(R, "A").Value <> Cells(R - 1, "A").Value Then Rows(R).Insert
  Next
  For Each Cell In Columns("A").SpecialCells(xlConstants).Areas
    Cell.Resize(3).Clear
  Next
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
let A1 = fred
add alan to bottom of list, sort, so A1=alan and A2 = fred

do you really want to delete rows 1,2,3 ??????????????


Im sorry, I’m not following your suggestion. And yeah I think I have to. These are statistics and I’m trying to have the prior three instances’ average in each row. Since the first 3 will have data from a prior name, I see no other way than to clip 3 rows from each name.
 
Upvote 0
Give this macro a try...
Code:
Sub ClearFirstThreeNewNames()
  Dim R As Long, Cell As Range
  For R = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    If Cells(R, "A").Value <> Cells(R - 1, "A").Value Then Rows(R).Insert
  Next
  For Each Cell In Columns("A").SpecialCells(xlConstants).Areas
    Cell.Resize(3).Clear
  Next
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub


That worked perfectly. Thanks a million!
 
Upvote 0
Good Morning Rick,
Thank you again for your help. I have a quick follow up question. I'm considering trying to show the average of the previous 3 and 10 values in each row. I looked over the code you wrote and it seems as if I'd only need to change "Cell.Resize(3).Clear" subbing in the 10 for the 3. Do I have that right?
Thank you Sir!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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