LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Array takes 6x longer to process VLOOKUP than worksheet table

OK I follow now. My test results for the array vs range were even worse than
yours, about 10x slower

Using a range it's about 2x faster to pass a reference to the range
eg
wfn.VLookup(Lookup_Date, Range(Cells(1, 51), Cells(61, 58)), c, True)
is about 2x slower than
Set Table_Dates = Range(Cells(1, 51), Cells(61, 58))
x = wfn.VLookup(Lookup_Date, Table_Dates, c, True)

If you really want to keep everything out of cells, following is only about
2x slower -

Array_Match = Range("Table_Dates").Columns(1)
m = wfn.Match(Lookup_Date, Array_Match, 0)
x = Array_Dates(m, c)

If your data is sorted you can probably achieve fastest results entirely
with VBA, ie no use of worksheet functions (search "binary chop").

fwiw you can do -
Dim wfn As WorksheetFunction
Set wfn = Application.WorksheetFunction

In passing, although notably, if the lookup is a date-value and the first
column of the lookup array also holds dates I got incorrect results using
the array method - watch out for that!

Regards,
Peter T



"KG Old Wolf" wrote in message
...
Following are code snippets - the top example runs 6x faster than the
bottom
(10 seconds versus 60). The only change was the way the VLOOKUPs are
performed.

By "moving the table to an array" I simply meant that the top approach
uses
a table that is on the same worksheet as the rows that are used as input
to
the procedure. The bottom approach is intended to compare the efficiency
gained by having that same information contained in an array (which I
expected to be faster).

I believe the problem in the bottom approach is caused because the array
is
not "SET" in the way the table is in the top approach. The issue is that
I
can't seem to find any information on how to set / reference the array
data
any way other than what I have coded.

I hope this clarifies it for you.

Thanks for your advice,
Ken

++++++++++++++++++++++++++++++++++++++++++++++++++ +

Array_Dates = Range("Table_Dates")
...
........ Intervening code that remains the same in both examples
...........
Print_Line_Array(Output_Row_Number, 8) =
Application.WorksheetFunction.VLookup(Lookup_Date, Array_Dates, 2, True)
' Days In Month
Print_Line_Array(Output_Row_Number, 9) =
Application.WorksheetFunction.VLookup(Lookup_Date, Array_Dates, 5, True)
' Month Sequence Number
Print_Line_Array(Output_Row_Number, 10) =
Application.WorksheetFunction.VLookup(Lookup_Date, Array_Dates, 3, True)
' First Day In Month

+++++++++++++++++++++++++++++++++++++++++++++

Set Table_Dates = Range(Cells(1, 51), Cells(61, 58))
ActiveWorkbook.Names.Add Name:="Table_Dates", RefersTo:=Range(Cells(2,
51),
Cells(61, 58))
...
........ Intervening code that remains the same in both examples
...........
Print_Line_Array(8) = Application.WorksheetFunction.VLookup(Lookup_Date,
Table_Dates, 2, True) ' Days In Month
Print_Line_Array(9) = Application.WorksheetFunction.VLookup(Lookup_Date,
Table_Dates, 5, True) ' Month Sequence Number
Print_Line_Array(10) = Application.WorksheetFunction.VLookup(Lookup_Date,
Table_Dates, 3, True) ' First Day In Month






 
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
Automatic Calculation in Code Takes Longer than Worksheet [email protected] Excel Programming 3 January 8th 09 06:18 PM
Code takes a long time to process Sandy Excel Programming 1 June 19th 08 08:08 PM
Rerunning Macro takes longer after each consecutive use....Why MikeZz Excel Programming 3 April 12th 07 02:07 PM
Double-clicking cell with =A1 no longer takes you to A1 in v2003? GoDario27 Excel Discussion (Misc queries) 6 August 16th 05 03:31 PM
How to use a cell value as Table Array in VLOOKUP worksheet function willydlish Excel Discussion (Misc queries) 2 February 16th 05 02:47 AM


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

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"