Remove duplicates from specific rows

lunatu

Board Regular
Joined
Feb 5, 2021
Messages
77
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Hi,

Im using this macro to remove duplicates:

Sub RemoveDuplicates()

Dim rng As Range

Set rng = ThisWorkbook.Sheets("Sales Person 1").UsedRange

rng.RemoveDuplicates Columns:=5, Header:=xlYes

End S
ub

The problem is that it is deleting the whole row, inc data validation and formulas in empty cells. I want to remove only cells in columns D:L. Any idea how to fix the makro to remove duplicates but not to effect on empty rows in other columns?

EDIT: sorry about the misleading header, meant:

"Remove duplicates from specific cells"​

 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How about
VBA Code:
Sub RemoveDuplicates()

Dim rng As Range
With ThisWorkbook.Sheets("Sales Person 1")
   Set rng = Intersect(.UsedRange, .Range("D:L"))
End With
rng.RemoveDuplicates Columns:=2, Header:=xlYes

End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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