Deleting Duplicates VBA Issue

tlrobinson512

New Member
Joined
Jun 24, 2014
Messages
21
Hello my Excel Experts. I am hoping someone might be able to tell me where I going wrong with my latest dilemna. I currently have code written to open a workbook and search within the specified worksheet for a specified header. Once that header has been identified, I move that column to A:A. Easy stuff. Works fine.

THEN...

I have code to look for duplicates in column A:A and delete them, however the code will not work when insert directly below the first section of code. It works great as a stand alone code, but not embedded within the overall Sub I am working on. Any thoughts?? Code below.

Workbooks.Open ("C:\Users\klx380\Documents\Report Extractions\Preview Analysis Ext.xls")
FindString = "LOAN_NUM"
If Trim(FindString) <> "" Then
With Sheets("Reported_Loans_Exceptions").Range("1:1")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
ActiveCell.EntireColumn.Cut
ActiveSheet.Range("A:A").Insert Shift:=xlToRight
ActiveSheet.Range("A1").Select

'This section is being overlooked - Can't figure out why it won't run this.

LastRow = Range("A65536").End(xlUp).Row
For x = LastRow To 1 Step -1
If Application.WorksheetFunction.CountIf(Range("A1:A" & x), Range("A" & x).Text) > 1 Then
Range("A" & x).EntireRow.Delete
End If
Next x

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I was able to figure out the correct code to use. I replaced the above with

With ActiveSheet
Set Rng1 = Range("A1").End(xlDown)
Rng.RemoveDuplicates Columns:=Array(1), Header:=xlYes
End With

And it seems to be working!
 
Upvote 0
Obviously theres more code

but

With ActiveSheet
Set Rng1 = Range("A1").End(xlDown)
Rng.RemoveDuplicates Columns:=Array(1), Header:=xlYes
End With

But the range names appear to be a miss match
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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