Combine multiple data based on cell value - macro need

scorpio3st

New Member
Joined
Sep 7, 2021
Messages
22
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I have a sheet where I need duplicate values combine into last duplicate value and combine all previous duplicate values into last one.
Example:
Lets say I have invoice with 5 different item numbers and need separate it with symbol "|"
1b1c1d1f1g
invoicea
1​
b
1​
c
1​
d
1​
e
1​
f
1​
g
1​
a|b|c|d|e|f|g
20​
fd
20​
df
20​
as
20​
yvxc
20​
asd
20​
cxb
20​
hkj
20​
cvn
20​
jkhl
20​
bc n
20​
klhj
20​
nv
20​
ycx
20​
as
20​
cyx
20​
mnv
20​
fd|df|as|yvxc|asd|cxb|hkj|cvn|jkhl|bc n|klhj|nv|ycx|as|cyx|mnv

Thanks.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,
Try...
VBA Code:
Sub test()
    Dim prf$, comb$, i&
    prf = Cells(2, 2).Value
    comb = ""
    For i = 2 To Cells(Rows.Count, 2).End(3).Row
        comb = comb & "|" & Cells(i, 4).Value
        If Cells(i + 1, 2).Value <> prf Then
            Cells(i, 6).Value = prf
            Cells(i, 7).Value = Mid(comb, 2)
            prf = Cells(i + 1, 2).Value
            comb = ""
        End If
    Next i
End Sub
 
Upvote 0
Solution
Hi,
Try...
VBA Code:
Sub test()
    Dim prf$, comb$, i&
    prf = Cells(2, 2).Value
    comb = ""
    For i = 2 To Cells(Rows.Count, 2).End(3).Row
        comb = comb & "|" & Cells(i, 4).Value
        If Cells(i + 1, 2).Value <> prf Then
            Cells(i, 6).Value = prf
            Cells(i, 7).Value = Mid(comb, 2)
            prf = Cells(i + 1, 2).Value
            comb = ""
        End If
    Next i
End Sub
Hi, Thanks. It is working great.
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

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