Thread: [Solved] deleting blanks and commas
View Single Post
 
Old 03-18-2017, 02:58 PM
FUGMAN FUGMAN is offline Windows 10 Office 2016
Banned
 
Join Date: Feb 2017
Posts: 55
FUGMAN is on a distinguished road
Default

A B C
FACILITY ZIP CODE STATE
AAAAAAA 111111 ?? ROW 7
BBBBBB 22222 ?? ROW 8
CCCCCC 333333 KY ROW 9
EEEEE 555555 MI ROW 10
DDDDDD 444444 AK ROW 11

Sub Remove_Dupes()
'ActiveSheet.Unprotect
' Remove_Dupes Macro

Dim lr As Long, r As Long, wr As Long
Application.ScreenUpdating = False
'row to write to
wr = Sheets("dupesheet").Cells(Rows.Count, 1).End(xlUp).Row + 1
'rows to check for dupes
With Sheets("FACILITY RECORDS")
'last row
lr = .Cells(Rows.Count, "A").End(xlUp).Row
'start at bottom row and work up
For r = lr To 2 Step -1
If .Cells(r, 1) = .Cells(r - 1, 1) Then
'compare the two rows
' credit Tim Williams ~~~ with great explanation at
' http://stackoverflow.com/questions/1...ows-in-a-sheet
If Join(Application.Transpose(Application.Transpose(. Cells(r, 1).EntireRow.Value)), "") = _
Join(Application.Transpose(Application.Transpose(. Cells(r - 1, 1).EntireRow.Value)), "") Then
'copy and delete if equal
.Cells(r, 1).EntireRow.Copy Sheets("dupesheet").Cells(wr, 1)
.Cells(r, 1).EntireRow.Delete
wr = wr + 1
End If
End If
Next r
End With
Application.ScreenUpdating = True
ActiveSheet.Protect
'
End Sub

I get the error even with this small sample. Wondering if my excel software is wacked out
Reply With Quote