LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
fra fra is offline
external usenet poster
 
Posts: 4
Default looping through ranges: how to speed up?


Hi all,

I need to loop through 2 ranges (same size, eg A2:A200, B2:B200)
a row at a time, check if the value in the second row is
equal to a specific cell and, if it is, add the value of the
first row to a collection.

I wrote this udf that works fine... but is SLOW!
How could I speed it up?

----------------------------
Public Function foo(rng1 As Range, rng2 As Range, cell) As Long
Dim x As Range
Dim i As Long
Dim unique_cod As New Collection

On Error Resume Next
i = 1
For Each x In rng1
If cell = rng2.Cells(i, 1) Then
'Debug.Print x; " <- "; x.Text; Cstr(x)
unique_cod.Add x, CStr(x)
End If
i = i + 1
Next x

'collection dump
'For i = 1 To unique_cod.Count
' Debug.Print unique_cod(i)
'Next i

foo = unique_cod.Count
End Function
-----------------------------

Thank you in advance, this ng is great!

Best regards,
Francesco
 
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
LOOPING multiple ranges Jase Excel Discussion (Misc queries) 1 April 7th 08 06:21 PM
Looping in VB with cell ranges Freeman Excel Worksheet Functions 2 January 22nd 06 12:14 PM
Looping through named ranges Tim[_38_] Excel Programming 1 May 10th 04 07:20 PM
Looping through Ranges of Rows MS News Excel Programming 6 December 9th 03 06:13 AM
Looping through Ranges of Rows MS News Excel Programming 0 December 8th 03 11:42 AM


All times are GMT +1. The time now is 10:18 PM.

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

About Us

"It's about Microsoft Excel"