Clear contents for duplicates in range

123excel

New Member
Joined
Jan 18, 2017
Messages
34
Hi, I am trying to clear the contents (not deleting) for duplicates of the Range A36:G36 and downwards (only the duplicated values should be deleted, the original should not be cleared).

Right now I have some code that do almost what I am after. The problem is that it is clearing the full row, not just range A:G.

How can I make it work with just the Range and not the full row?


Here is the code I got:


Code:
Sub RemoveDuplications()
Dim X As Long
For X = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Application.WorksheetFunction.CountIf(Range("A36:A" & X), Range("A" & X).Text) > 1 Then Rows(X).ClearContents
Next
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try something like:
Code:
Sub RemoveDuplications()

Dim X As Long


For X = 37 To Range("A" & Rows.Count).End(xlUp).Row
    If Application.WorksheetFunction.CountIf(Range("A36:A" & X), Range("A" & X).Text) > 1 Then
        Intersect(Range("A:G"), Rows(X)).ClearContents
    End If
Next


End Sub
Your code was missing the Intersect-part. Also, I understood that you wanted to look duplicates from A36 down so I started my X from 37.
 
Upvote 0
Another option
Code:
Sub I23excel()
   Dim cl As Range
   
   With CreateObject("scripting.dictionary")
      .CompareMode = 1
      For Each cl In Range("A36", Range("A" & Rows.Count).End(xlUp))
         If Not .Exists(cl.Value) Then .Add cl.Value, Nothing Else cl.Resize(, 7).ClearContents
      Next cl
   End With
End Sub
 
Upvote 0
Thank you both Misca and Fluff!

Miscas version worked great so I am going to stick to that.

Thanks a lot for both your help! I really appreciate it.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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