problem with code- removing duplicate rows

heathball

Board Regular
Joined
Apr 6, 2017
Messages
135
Office Version
  1. 365
Platform
  1. Windows
I just realised my code is not what i thought it was.

it works well to remove duplicate rows...
But...
if in column A, there is a date or number or something else? perhaps anything but text
....it treats column A as the criteria for looking at duplicates.
for example, leaving only 1 line for each date, even though....the rows are different.

How can i change this code, so that it is an "authentic"
"duplicate row remover"
nothwithstanding what is happening with cell format in column A, or in any column.

just simply removing the duplicate rows on the active sheet, and leaving one of each of the original rows

Thanks in advance.



VBA Code:
Option Explicit
Sub RemoveDuplicatesRows()

  Dim AB As Long
    AB = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
         
Dim dataRange As range
Dim colNum As Variant
Dim I As Integer
Set dataRange = selection
ReDim colNum(0 To dataRange.Columns.Count - 1)
For I = 0 To UBound(colNum)
colNum(I) = I + 1
Next I
dataRange.RemoveDuplicates Columns:=(colNum), Header:=xlYes

Dim lastRow As Long
    lastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
MsgBox "to start with......" & AB & vbNewLine & "remaining are......" & lastRow

Set dataRange = Nothing
Set colNum = Nothing
End Sub
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
i have just worked out, that if i select the entire sheet, by any process, example 'usedrange', ........it works as intended
which i can add to the code at the beginning.

But just from a theoretical standpoint, it would interesting to know how to achieve it. (assuming it is possible)
 
Upvote 0
the answer is actually in the code...
Set dataRange = selection
so that makes the post solved.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,178
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