(VBA) Search duplicates in column then work on whole rows

sh1ne

New Member
Joined
Jul 3, 2017
Messages
33
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,
I will describe you my problem as far as I can. I need help with a macro which fill search for duplicates based on column D and IF THERE IS duplicated row, he will be always in next following row. Then all what we need to do is delete the duplicated rows, but add values from columns. There is no situation where the repeated row has a value in the column where the previous row has something in it. Let me show you my problem:
ABCD
1QWE
2WER
3ERT
4ASD
2ASD
1SDF
2DFG
3FGH
1FGH
2FGH

<tbody>
</tbody>


How it should look after macro?
ABCD
1QWE
2WER
3ERT
24ASD
1SDF
2DFG
213FGH

<tbody>
</tbody>


As you see, ASD and FGH values got before 2 and 3 same rows with different values in columns, macro should merge 'em all and put values in one line. All duplicates won't have values in column B if first not duplicated row has something in it.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Jun05
[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] nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("D1", Range("D" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
    .Add Dn.Value, Dn
[COLOR="Navy"]Else[/COLOR]
    [COLOR="Navy"]For[/COLOR] n = 1 To 3
        [COLOR="Navy"]If[/COLOR] Not IsEmpty(Dn.Offset(, -n).Value) [COLOR="Navy"]Then[/COLOR]
            .Item(Dn.Value).Offset(, -n).Value = Dn.Offset(, -n).Value
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,576
Messages
6,125,633
Members
449,242
Latest member
Mari_mariou

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