View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
KG Old Wolf KG Old Wolf is offline
external usenet poster
 
Posts: 19
Default Array takes 6x longer to process VLOOKUP than worksheet table

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