I have such a document Excel

What formula needs to be put in order to make it so? Excel2

Names can be 1 and 20. Interested in how to get a column similar products. Manually go crazy 10 thousand. titles edit. Thank.

  • And what is considered similar? Same name? - Alexey Ten
  • Yes. For example, socks XXS -> similar Socks (XS, S, M, L, XL, XXL) Socks XS-> similar Socks (XXS, S, M, L, XL, XXL)

1 answer 1

Place the code in the common module:

Sub SimilarСode() Dim aData(), aRes() Dim sStr As String Dim i As Long, n As Long With ActiveSheet i = .Cells(.Rows.Count, 1).End(xlUp).Row If i < 2 Then Exit Sub aData = .Range("A1:C" & i).Value ReDim aRes(1 To i, 1 To 1): aRes(1, 1) = "Похожие продукты" For i = 2 To UBound(aData) For n = 2 To UBound(aData) If aData(i, 1) = aData(n, 1) Then If i <> n Then sStr = sStr & ", " & aData(n, 3) End If Next n aRes(i, 1) = Mid$(sStr, 3): sStr = "" Next i .Range("D1").Resize(UBound(aRes), 1).Value = aRes End With MsgBox "OK", 64, "" End Sub 

Run: put the cursor on the header (or working line) of the code and press F5 . If the processing is not one-time, it is better to create a button on the sheet and assign it to launch a macro.

The sheet on which the table with articles is located must be active. If for some reason another sheet is active, replace the line

 With ActiveSheet 

On the line with the name of the sheet you need:

 With Worksheets("Лист1") 

After processing in the column D lists of articles of goods with the same name will be displayed.

It is more correct if you assign the “Text” cell format to columns C and D. Item number is often not a number and data will be scattered in the cell left and right.

Another example of a possible error - the article with the leading zeros "00101" in the cell with the common format is converted to 101.

  • Thank you very much! May the force be with you, Jedi!) - Valera Kononenko