Duplicated strings text in different order

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
318
Hi excel gurus!

I was wondering if someone could help me with the following:

I have a list of words such as

Black T Shirt
T Shirt Black
black t shirt

Irrespective of case they are duplicated strings albeit the text being in a different order, is it possible to use excel to group these duplicates together? I.e. the above would be in column A however beside it would be a duplicated batch number I.e. for this "batch" it would be 1

Many thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You will need to post as many samples containing the different text. But this works for the sample =IFERROR(IF(SEARCH("Black",A1),1,""),"")
 
Last edited:
Upvote 0
Test this in a copy of your workbook to see if it does what you want.
If not, please provide more details/samples of data & expected results.

Rich (BB code):
Sub GroupNumbers()
  Dim d As Object, AL As Object
  Dim a As Variant
  Dim bits() As String, s As String
  Dim i As Long, j As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  Set AL = CreateObject("System.Collections.ArrayList")
  d.CompareMode = 1
  a = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    bits = Split(a(i, 1))
    For j = 0 To UBound(bits)
      AL.Add bits(j)
    Next j
    AL.Sort
    s = Join(AL.ToArray)
    AL.Clear
    If d.exists(s) Then
      a(i, 1) = d(s)
    Else
      d(s) = d.Count + 1
      a(i, 1) = d.Count
    End If
  Next i
  Range("B2").Resize(UBound(a)).Value = a
End Sub


My sample data & results:

Excel Workbook
AB
1ItemGroup
2Black T Shirt1
3T Shirt Black1
4black t shirt1
5White T Shirt2
6T Shirt White2
7Blue Tie3
8White t shirt2
9Green shirt4
10tie blue3
11T shirt green5
Sheet1
 
Upvote 0
Peter

If i understood correctly your code i noticed the use of ArrayList to sort alphabetically the strings' bits, and a Dictionary to number the groups.
Very clever!

M.
 
Upvote 0
Peter

If i understood correctly your code i noticed the use of ArrayList to sort alphabetically the strings' bits, and a Dictionary to number the groups.
Very clever!

M.
Thanks Marcelo. Yes, that's exactly what I was trying to do - and using CompareMode = 1 for the dictionary to remove case-sensitivity.
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,492
Members
449,166
Latest member
hokjock

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