VBA filter duplicates in column and copy-filtered area to another location

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

I got a column "I" with values bringing back from formula sum</SPAN></SPAN>
I want to filter all duplicates of this "I" column and copy all C:I columns to location columns L:R</SPAN></SPAN>

Example....</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQR
1
2
3
4
5n1n2n3n4n5n6Sumn1n2n3n4n5n6Sum
6011121660517625
7003200582620725
8014321111040139
9225042150201249
10306053171302309
1121412122213137116
1231524333025250216
1341630443151103717
1451740553602304817
156051762520053010
168262072502160110
179074182910071211
1811185302800182011
1906140011402124426
2007262017503135026
2128083021
2200290112
231040139
240201249
251302309
2624034114
2745045220
2813137116
2925250216
3030061414
3140072619
3251103717
3302304817
3413405013
3524516018
3603342315
3720053010
3802160110
3910071211
4000182011
4150019318
42601210423
43010411622
44130512728
45200713022
4602180011
4713291117
48240102220
49301113321
50402124426
51503135026
52015140020
53000151016
54011162020
55132173026
Sheet1
Cell Formulas
RangeFormula
I6=SUM(C6:H6)
I7=SUM(C7:H7)


Thanks In Advance </SPAN></SPAN>
Using version 2000</SPAN></SPAN>

Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about
Code:
Sub motilulla()
   Dim Cl As Range
   Dim Ky As Variant
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("I6", Range("I" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Array(False, Cl.Offset(, -6))
         Else
            .Item(Cl.Value) = Array(True, Union(Cl.Offset(, -6), .Item(Cl.Value)(1)))
         End If
      Next Cl
      For Each Ky In .Keys
         If .Item(Ky)(0) Then
            For Each Cl In .Item(Ky)(1).Areas
               Cl.Resize(, 7).Copy Range("L" & Rows.Count).End(xlUp).Offset(1)
            Next Cl
         End If
      Next Ky
   End With
End Sub
 
Upvote 0
How about
Code:
Sub motilulla()
   Dim Cl As Range
   Dim Ky As Variant
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("I6", Range("I" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Array(False, Cl.Offset(, -6))
         Else
            .Item(Cl.Value) = Array(True, Union(Cl.Offset(, -6), .Item(Cl.Value)(1)))
         End If
      Next Cl
      For Each Ky In .Keys
         If .Item(Ky)(0) Then
            For Each Cl In .Item(Ky)(1).Areas
               Cl.Resize(, 7).Copy Range("L" & Rows.Count).End(xlUp).Offset(1)
            Next Cl
         End If
      Next Ky
   End With
End Sub
Thank you Fluff, I understand that my title is wrong, and your code is working fine, as it should be according to the title and also as it is explained required.</SPAN></SPAN>

What I am looking for actually is to filter the consecutive duplicate rows, as shown in post#1 (in red).
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Last edited:
Upvote 0
In that case, how about
Code:
Sub motilulla()
   Dim Cl As Range, Strt As Range
   
   For Each Cl In Range("I6", Range("I" & Rows.Count).End(xlUp))
      If Cl.Value = Cl.Offset(1).Value Then
         If Strt Is Nothing Then Set Strt = Cl
      ElseIf Not Strt Is Nothing Then
         Range(Strt.Offset(, -6), Cl).Copy Range("L" & Rows.Count).End(xlUp).Offset(1)
         Set Strt = Nothing
      End If
   Next Cl
End Sub
 
Upvote 0
In that case, how about
Code:
Sub motilulla()
   Dim Cl As Range, Strt As Range
   
   For Each Cl In Range("I6", Range("I" & Rows.Count).End(xlUp))
      If Cl.Value = Cl.Offset(1).Value Then
         If Strt Is Nothing Then Set Strt = Cl
      ElseIf Not Strt Is Nothing Then
         Range(Strt.Offset(, -6), Cl).Copy Range("L" & Rows.Count).End(xlUp).Offset(1)
         Set Strt = Nothing
      End If
   Next Cl
End Sub
Fluff, sorry for the inconvenience, thank you for rewriting the new code it is just perfect! What I had in my mind :beerchug: </SPAN></SPAN>

Thank you for you're twice helps
</SPAN></SPAN>

Have a nice weekend
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti :-D
</SPAN></SPAN>
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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