dnickelson
Board Regular
- Joined
- Oct 30, 2003
- Messages
- 118
I've seen a number of posts relating to creating a 'distinct' list of items based off a list that may or may not contain duplicates. What I'm wondering is if the code I'm using would be useful, or whether it would miss some important feature, or if it's inefficient past being usable, etc.
I do know that it's probably frightenly inefficient from a redundant use of sheet and range qualifiers, but haven't gotten around to smoothing that out.
Just curious because I'm looking for a reusable way to perform this task (currently have a replated post suggesting the use of sql syntax, but that might just be wishful thinking).
Thanks,
-Dan
Code:
Sub uniquelist()
ss = "Sheet1" 'sheet unfiltered list is located
sr = 1 'row unfiltered list begins
sc = 1 'column unfiltered list is located
srend = Sheets(ss).Cells(65535, sc).End(xlUp).Row
rs = "Sheet1" 'sheet filtered list should be placed in
rr = 1 'row filtered list should start
rc = 5 'column to place filtered list
startr = rr
Sheets(rs).Range(Sheets(rs).Cells(rr, rc), Sheets(rs).Cells(Sheets(rs).Cells(65535, 1).End(xlUp).Row, rc)).ClearContents
For r = sr To srend
If Sheets(ss).Cells(r, sc) <> "" Then
If Application.WorksheetFunction.CountIf(Sheets(rs).Range(Sheets(rs).Cells(startr, rc), Sheets(rs).Cells(rr + 1, rc)), Sheets(ss).Cells(r, sc)) = 0 Then
Sheets(rs).Cells(rr, rc) = Sheets(ss).Cells(r, sc)
rr = rr + 1
End If
End If
Next
End Sub
I do know that it's probably frightenly inefficient from a redundant use of sheet and range qualifiers, but haven't gotten around to smoothing that out.
Just curious because I'm looking for a reusable way to perform this task (currently have a replated post suggesting the use of sql syntax, but that might just be wishful thinking).
Thanks,
-Dan