thecoffeeguy
New Member
- Joined
- Nov 30, 2005
- Messages
- 8
Hello everyone!
Im having trouble running a dedupe macro that I found on this board. Here is the macro I am using:
Im running this against a spreadsheet that has 6 columns, and about 22000 rows. I am deduping based on phone numbers that are entered in the spreadsheet as follows:
123-123-1234
Now, in the macro, I changed the column to be checked to the column the phone numbers are in, which is D and I set it to 4. I also get the column to temporary hold the formula to G, as the last column in the sheet is F.
Everytime I run the macro, nothing happens and im stumped.
Anyone have any ideas?
I appreciate it.
thecoffeeguy
Im having trouble running a dedupe macro that I found on this board. Here is the macro I am using:
Code:
Option Explicit
Sub Column_Sort_DeleteDuplicates_()
' Code by
Dim col%, c%, x%, rng As Range
col = 4 '1 is the column number to search - change it as required
' I.E. Column A = 1, Column B = 2, etc
' Set the column number of the column to store temporary formula
c = Range([G1], ActiveSheet.UsedRange).Columns.Count + 1
' Exit if the used columns=256 (instead of exiting, could amend thecode _to look for a column containing no data to use for the temporaryformula)
If c > 256 Then Exit Sub
' Set the column offset(from the search column to the temp. formulacolumn)
x = col - c
' Turn off screen-updating and set calculation to manual _
(if required, could add a test to check if calculation is already set _
to manual, in which case would not want to set to automatic at the end
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
' Set the range to contain the temp. formula
Set rng = Range(Cells(1, c), Cells(65536, col).End(xlUp).Offset(, -x))
With rng
' Sort the data by the search column
.EntireRow.Sort Key1:=rng(1, x + 1), Order1:=xlAscending, Header:=xlNo
' Put temp. value in the fors cell of the temp.column
rng(1) = 1
' Enter the temp formula that identifies duplicates
.Offset(1).FormulaR1C1 = "=IF(RC[" & x & "]=R[-1]C[" & x & "],"""",1)"
' Convert the formula to value
.Offset(1) = .Offset(1).Value
' Sort entire rows by the temp. formula result so as to group all of_the rows to be deleted at the end
.EntireRow.Sort Key1:=rng(1), Order1:=xlAscending, Header:=xlNo
' Error handler in case there are no duplicates
On Error Resume Next
' Delete the duplicate rows
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
' Reset error handling
On Error GoTo 0
End With
' Delete the temp. formula column
Columns(c).Delete
' Reset the sheet's last used cell
ActiveSheet.UsedRange
' Turn on screen-updating and set calculation to automatic
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
End Sub
Im running this against a spreadsheet that has 6 columns, and about 22000 rows. I am deduping based on phone numbers that are entered in the spreadsheet as follows:
123-123-1234
Now, in the macro, I changed the column to be checked to the column the phone numbers are in, which is D and I set it to 4. I also get the column to temporary hold the formula to G, as the last column in the sheet is F.
Everytime I run the macro, nothing happens and im stumped.
Anyone have any ideas?
I appreciate it.
thecoffeeguy