Using an Array instead of a Vlookup to improve speed
Dim v as Variant
Dim j as Long, i as Long
j = some index number
v = Range("Table").value
for i = l to ubound(v,1)
if v(i,1) = MyArray(j,1) then
MyArray(j,4) = "Existing Product"
exit for
end if
Next
if isemty(MyArray(j,4)) then
MyArray(j,4) = "New Product"
end if
--
Regards,
Tom Ogilvy
"Frank & Pam Hayes" wrote in message
news:KBlKe.9141$0d.3629@trnddc02...
I have an two dimensional array (MyArray) that describes 5000 invoices.
MyArray(i, 1) is the PRODUCT
MyArray(i, 2) is the VOLUME
MyArray(i, 3) is the REVENUE
MyArray(i, 4) is the TYPE
I am using Application.Vlookup to lookup the PRODUCT in a named range on a
worksheet to see if this is a product I sold in the previous period. If
the
Vlookup is successful, I put "Existing Product" in MyArray(i, 4). If the
vlookup returns an error (using FALSE as the last argument), then I put
"New
Product" in MyArray(i, 4).
The Application.Vlookup is a bit slow. Can someone point me to a VBA
example where the author wrote the target range into a second Array and
then
used a For Next loop to perform the same basic logic as the vlookup would?
Thanks,
Frank Hayes
|