Remove Duplicates - runtime error 91 - Don't know how to fix.

mysterious-dr-x

Board Regular
Joined
Jul 29, 2011
Messages
51
It occures to me that using & learning vba concurrently is probably a bad idea. Now, however, it is far too late for that. My main issue is that I don't know how to fix any errors that turn up & I need a little help.

I'm trying to set up a little macro in excel 2007 that will determine where the end of the data is, select it all, then remove any duplicates. (This will autorun after additional data has been added to the range, although that is not currently coded.)

The code below is what I have at this time, & the debugger claims that the error is occuring on the "LR = .....etc" row.

I admit, this code has partially been created with the "record macro" function, & I know that there may be a better way. Please don't hold it against me.


Code:
Dim LR As Long
Dim ws As Worksheet
 
    LR = ws.Range(ws.Rows.Count).End(xlUp).Row
    Rows("9:" & LR).Select
    ActiveSheet.Range("9:" & LR).RemoveDuplicates Columns:=Array(1, 2, 3, 4, _
         5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, _
         24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37),
         Header:=xlNo
 
End Sub
 
In the example below, I started with the even number rows with fill color blue and bold font.
Excel Workbook
ABCD
91234
10DuplicateDuplicateDuplicateDuplicate
1181101
124511
13DuplicateDuplicateDuplicateDuplicate
146218
152184
16DuplicateDuplicateDuplicateDuplicate
175114
Before


After running the code all "Duplicates" except the first have been deleted and the rows shifted up.
Excel Workbook
ABCDE
912345
10DuplicateDuplicateDuplicateDuplicateDuplicate
11811015
1245114
1362184
1421847
1551149
After


Do you get a different result?
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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