Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete matching cells
On Mon, 16 Jan 2012 18:50:24 -0500, GS wrote:
We can shave off even more time if we eliminate the checks when adding items to the dictionary because the dictionary won't allow dupes... Your efforts prompted me to study whether dictionary or collection would work faster. And it turns out that my "prune" routine, which eliminates duplicates in Col A, when rewritten using Collections, runs in about 1/6 the time! My last effort, using dictionaries for col a and col b, on the Jim style database (240,000 entries colA; 360,000 entries col b) took about 29 sec to run. The following process that same data base in 5.5 seconds!! ============================= Option Explicit Sub PruneColA2() Dim ws As Worksheet Dim rColA As Range, rColB As Range Dim vColA As Variant, vColB As Variant Dim vResults As Variant Dim cColB As Collection Dim i As Long Dim lBlanks As Long Dim v As Variant Dim rDest As Range Set cColB = New Collection Set ws = ActiveSheet With ws Set rColA = Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp)) Set rColB = Range(.Cells(1, "B"), .Cells(.Rows.Count, "B").End(xlUp)) Set rDest = .Cells(1, 10) End With vColB = rColB vColA = rColA On Error Resume Next For i = LBound(vColB, 1) To UBound(vColB, 1) With cColB .Add Key:=vColB(i, 1), Item:=vColB(i, 1) End With Next i On Error GoTo 0 On Error GoTo NotUniqueItem For i = LBound(vColA, 1) To UBound(vColA, 1) cColB.Add Item:=vColA(i, 1), Key:=vColA(i, 1) Next i ReDim vResults(1 To UBound(vColA) - lBlanks, 1 To 1) i = 0 For Each v In vColA If v < "" Then i = i + 1 vResults(i, 1) = v End If Next v rDest.EntireColumn.ClearContents rDest.EntireColumn.NumberFormat = "@" Set rDest = rDest.Resize(rowsize:=UBound(vResults, 1)) rDest = vResults Exit Sub NotUniqueItem: vColA(i, 1) = "" lBlanks = lBlanks + 1 Resume Next End Sub ================================= |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete matching cells
I was thinking the same thing! I'll report back in a new thread as Jim
suggested... -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete matching cells
I like how you were able to eliminate the final If...Then construct.<g
-- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete matching cells
Uh.., I'm seeing that this approach raises a 'Type Mismatch' error in
the first loop where it loads colB into the collection. Also, this approach empties colA and raises an error trying to write the output array because the UBound(vColA) and lBlanks are the same value. What am I missing? -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete matching cells
On Mon, 16 Jan 2012 22:17:05 -0500, GS wrote:
Uh.., I'm seeing that this approach raises a 'Type Mismatch' error in the first loop where it loads colB into the collection. Also, this approach empties colA and raises an error trying to write the output array because the UBound(vColA) and lBlanks are the same value. What am I missing? If your data is numbers and not text strings, you can see that. Key has to be a string. It is probably safest to always use Key:=Cstr(x) That should have no affect on string data, but will convert numeric data to strings. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Delete all cells in range matching certain values | Excel Programming | |||
Help with Matching Text Fields - Then Moving the Matching Cells Side by Side | Excel Discussion (Misc queries) | |||
DELETE ROW 3 MATCHING CRITERIA | Excel Programming | |||
delete all matching rows | Excel Discussion (Misc queries) | |||
Perform Lookup and delete non matching rows? | Excel Programming |