Deleting some duplicated data - but not the entire column

mxman

New Member
Joined
Jun 8, 2006
Messages
46
I copied the following code from a microsoft example, however it removes the entire column of duplicated data. In my case, I only want to delete the data in rows 6 to 65536 of that column. How do I do that?
Can someone help me please?

The code to delete the entire column is this:-

Sub DeleteColumnDupes(strSheetName As String, strColumnLetter As String)
Dim strColumnRange As String
Dim rngCurrentCell As Range
Dim rngNextCell As Range

strColumnRange = strColumnLetter & "1"

Worksheets(strSheetName).Range(strColumnRange).Sort _
Key1:=Worksheets(strSheetName).Range(strColumnRange)
Set rngCurrentCell = Worksheets(strSheetName).Range(strColumnRange)
Do While Not IsEmpty(rngCurrentCell)
Set rngNextCell = rngCurrentCell.Offset(1, 0)
If rngNextCell.Value = rngCurrentCell.Value Then
rngCurrentCell.EntireRow.Delete
End If
Set rngCurrentCell = rngNextCell
Loop
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
Try changing the fifth line from:
Code:
strColumnRange = strColumnLetter & "1"
to:
Code:
strColumnRange = strColumnLetter & "6"
and let us know if that does it.
 

Forum statistics

Threads
1,136,518
Messages
5,676,324
Members
419,619
Latest member
jalme

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
Top