Filter Result through excel formula

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
534
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
HI, we have the following data where we have many entry in Sheet1 column A, here we have updated some demo data but we have many entries

Product Code
&TS4560&
&TS6484&
&TS2468&
&TS4560& (1)
&TS4560& (2)
&TS4560& (3)
&TS8470&
&TS8474&
&TS6484& (1)
&TS6484& (2)


Want this type of result in sheet 2, where if we have sub code then it will come in column D as shown in Sheet2

Product CodeSub Code
&TS4560&&TS4560& (1)
&TS4560& (2)
&TS4560& (3)
&TS6484&
&TS2468&
&TS8445&&TS8445& (1)
&TS8445& (2)
&TS8474&


we required formula, if it is not possible with formula then vba please
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi @Vishaal

This data in sheet1 does not exist, I guess it is a typo:
1686074645874.png


But continuing with the criteria, according to the data on sheet1 the result should be:
Dante Amor
ABCD
1Product CodeSub Code
2&TS4560&&TS4560& (1)
3&TS4560& (2)
4&TS4560& (3)
5&TS6484&&TS6484& (1)
6&TS6484& (2)
7&TS2468&
8&TS8470&
9&TS8474&
Sheet2



I propose the following solution with a macro:
VBA Code:
Sub codes()
  Dim a As Variant, b As Variant, ky As Variant, itm As Variant
  Dim dic As Object
  Dim i As Long, k As Long
  Dim s As String
 
  a = Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("A" & Rows.Count).End(3))
  ReDim b(1 To UBound(a, 1), 1 To 4)
  Set dic = CreateObject("Scripting.Dictionary")
 
  For i = 1 To UBound(a)
    If InStr(1, a(i, 1), "(") = 0 Then s = a(i, 1) Else s = Trim(Split(a(i, 1), "(")(0))
    dic(s) = dic(s) & "|" & a(i, 1)
  Next
 
  For Each ky In dic.keys
    k = k + 1
    b(k, 1) = ky
    itm = Split(dic(ky), "|")
    For i = 2 To UBound(itm)
      b(k, 4) = itm(i)
      k = k + 1
    Next
    If UBound(itm) > 1 Then k = k - 1
  Next
  Sheets("Sheet2").Range("A2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
End Sub
--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution

Forum statistics

Threads
1,216,818
Messages
6,132,883
Members
449,766
Latest member
Morfildor

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