LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default VBA Dictionary Trim to N smallest items

I have a dictionary and I am trying to trim it down to the N smallest
items. For example, myDict usually contains around 3500 to 5500 items,
and I only want the smallest 10 (usually). The code I'm using now is :

'// loop, removing largest distance until we're down to the number of
points we want
Do Until myDict.Count = N
maxDist = -1
For Each i In myDict.Keys
If myDict.Item(i) maxDist Then
maxDist = myDict.Item(i)
mx = i
End If
Next i
myDict.Remove mx
Loop

The problem is that this is super slow; it loops through thousands of
times, and this snippet of code is used thousands of times too. Is
there a faster way to get the smallest N items?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP Trim vs. No Trim Kigol Excel Programming 2 October 3rd 07 05:14 PM
Defining Variable Type for Items and Keys in Dictionary ExcelMonkey Excel Programming 5 May 4th 07 09:22 PM
looping through items in a dictionary Abe[_4_] Excel Programming 4 July 8th 06 10:39 AM
VBA Trim and Application.worksheetfunction.Trim Hari Prasadh Excel Programming 3 January 19th 05 02:22 PM
Trim like worksheet Trim Bob Phillips[_5_] Excel Programming 0 August 20th 03 07:10 PM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"