Combining duplicates and replacing blanks

ur_friend_mac

New Member
Joined
Apr 10, 2018
Messages
2
Hello everyone!


I have after searching a while, and writing this post a few times due to browser issues, come to seek help.


I'm looking for a way (VBA or other) to combine duplicate rows while merging data streching over multiple columns. Not to sum the values, but to remove any duplicate (or blank) values (and rows). The data is spread over multiple sheets but can be copied into one to make things easier. I'll try to show an example below, please feel free to ask, as I am unsure if my goals are undestandable. The original data spreads over more columns than the example shown.


The solutions I have seen, and tried, has not achieved exactly what I'm after.


Thankful for any suggestions!

So I want this: (A2:A12)..

Item no. Shelf no. Order no. --->
111 a
222 b2
3333
4444
222 b
444 d
1111
333 c
111 1
222
111

<tbody>
</tbody>


... To become this (order not specific):

111 a1
222 b2
333 c3
444 d4

<tbody>
</tbody>

Have a nice day!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Run code on Data in new sheet, for results on sheet2, starting "A2".

Code:
[COLOR=navy]Sub[/COLOR] MG10Apr20
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Ray [COLOR=navy]As[/COLOR] Variant, Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] c [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
Ray = ActiveSheet.UsedRange
ReDim nray(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
    [COLOR=navy]For[/COLOR] n = 2 To UBound(Ray, 1)
        [COLOR=navy]If[/COLOR] Not .Exists(Ray(n, 1)) [COLOR=navy]Then[/COLOR]
              c = c + 1
            [COLOR=navy]For[/COLOR] Ac = 1 To UBound(Ray, 2)
                 nray(c, Ac) = Ray(n, Ac)
            [COLOR=navy]Next[/COLOR] Ac
            .Add Ray(n, 1), c
        [COLOR=navy]Else[/COLOR]
            [COLOR=navy]For[/COLOR] Ac = 1 To UBound(Ray, 2)
                [COLOR=navy]If[/COLOR] Not IsEmpty(Ray(n, Ac)) [COLOR=navy]Then[/COLOR]
                     nray(.Item(Ray(n, 1)), Ac) = Ray(n, Ac)
                [COLOR=navy]End[/COLOR] If
            [COLOR=navy]Next[/COLOR] Ac
        [COLOR=navy]End[/COLOR] If
    [COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] With
[COLOR=navy]With[/COLOR] Sheets("Sheet2").Range("A2").Resize(c, UBound(Ray, 2))
   .Value = nray
   .Columns.AutoFit
   .Borders.Weight = 2
[COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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