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
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