Hi
using excel XP...
am trying to use a macro to exclude duplicate cases, as can't seem to permanently do so with adv filter>exclude duplicates etc despite copying to another data sheet etc.
Data example:
ID Age INR blood result
2 83 2.4
2 83 2.9
2 83 1.9
2 83 5
3 70 3.8
3 70 4
3 70 8
3 70 3
I found this code:
Sub DelDups_OneList()
Dim iListCount As Integer
Dim iCtr As Integer
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through.
iListCount = Sheets("Sheet4").Range("A1:A2000").Rows.Count
Sheets("Sheet4").Range("A1").Select
' Loop until end of records.
Do Until ActiveCell = ""
' Loop through records.
For iCtr = 1 To iListCount
' Don't compare against yourself.
' To specify a different column, change 1 to the column number.
If ActiveCell.Row <> Sheets("Sheet4").Cells(iCtr, 1).Row Then
' Do comparison of next record.
If ActiveCell.Value = Sheets("Sheet4").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Sheet4").Cells(iCtr, 1).Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
End If
Next iCtr
' Go to next record.
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
.....But it doesn't exclude all the duplicates, often leaving 5 or so of the same case...the 'ID' column is 2letters and 4 numbers if thats any use and i have about 15000 rows of data
any ideas?? -thanks in advance!
Jim
using excel XP...
am trying to use a macro to exclude duplicate cases, as can't seem to permanently do so with adv filter>exclude duplicates etc despite copying to another data sheet etc.
Data example:
ID Age INR blood result
2 83 2.4
2 83 2.9
2 83 1.9
2 83 5
3 70 3.8
3 70 4
3 70 8
3 70 3
I found this code:
Sub DelDups_OneList()
Dim iListCount As Integer
Dim iCtr As Integer
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through.
iListCount = Sheets("Sheet4").Range("A1:A2000").Rows.Count
Sheets("Sheet4").Range("A1").Select
' Loop until end of records.
Do Until ActiveCell = ""
' Loop through records.
For iCtr = 1 To iListCount
' Don't compare against yourself.
' To specify a different column, change 1 to the column number.
If ActiveCell.Row <> Sheets("Sheet4").Cells(iCtr, 1).Row Then
' Do comparison of next record.
If ActiveCell.Value = Sheets("Sheet4").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Sheet4").Cells(iCtr, 1).Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
End If
Next iCtr
' Go to next record.
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
.....But it doesn't exclude all the duplicates, often leaving 5 or so of the same case...the 'ID' column is 2letters and 4 numbers if thats any use and i have about 15000 rows of data
any ideas?? -thanks in advance!
Jim