deleting identical numbers

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
first thing first, is it ok to ask several similar questions in one thread or should i split them?

so my question is similar to my last one (in other thread from today)
i want to delete all rows containing 3 identical numbers, in any order
example as follow

example.xlsx
ABCD
15111
21118
34944
41212
51248
61351
71249
88246
92242
22
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Will there always be only 4 numbers in any row?
 
Upvote 0
I think this macro should work...
VBA Code:
Sub DeleteRepeatThreeOrMoreInRow()
  Dim R As Long, Rng As Range
  Set Rng = Range("A1:D" & Cells(Rows.Count, "A").End(xlUp).Row)
  For R = 1 To Rng.Rows.Count
    If Evaluate(Replace("COUNTIF(@,MODE(@))>2", "@", Intersect(Rng, Rows(R)).Address)) Then
      Cells(R, "A").Value = "#N/A"
    End If
  Next
  Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End Sub
 
Upvote 0
Solution
In Power Query:

Power Query:
let
    gte3 = (lst as list) as logical => List.Count(lst) - List.Count(List.RemoveMatchingItems(lst,{List.Mode(lst)})) >2,
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    lst = Table.ToRows(Source),
    lst1  = List.Accumulate({0..List.Count(lst)-1}, {}, (s,c)=> if gte3(lst{c}) then s else s & {lst{c}}),
    Result = Table.FromRows(lst1, Table.ColumnNames(Source))
in
    Result

Book2
ABCDEFGHI
1Column1Column2Column3Column4Column1Column2Column3Column4
251111212
311181248
449441351
512121249
612488246
71351
81249
98246
102242
Sheet2
 
Upvote 0
for joe: yes
for rick: Excel-lent!
for gordon: don't know what is power query
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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