VBA Evaluate Range and VLOOKUP

DocAElstein

Banned user
Joined
May 24, 2014
Messages
1,336
Hi,
As a beginner I may be going a bit above my head!!

After studying and participating at some considerable length in Threads and links to do with using the Evaluate function to speed things up, I thought I understood it. Here are some of those links and Threads. (www.excelfox.com/forum/f22/concatenating-balls-1891/ VBA Trick of the Week :: Avoid Loop for Range Calculations – Evaluate | Useful Gyaan )

. So … the following simplified example File (XL2007 .xlsm)
https://app.box.com/s/pr78mhna00advvhsrmvi
has a Spreadsheet LEFT Function and a Spreadsheet VLOOKUP Function

The results look good! (That is to say wot I expect!) :-



Book1
ABCD
1Produnt
2Name
3Chocolate-europe aroma4Choc
4Chocolate-Cookies0Choc
5Banana-Chocolate-Split10Bana
6Limette-Ksekuchen16Lime
7Erdbeere-Quark8Erdb
8Erdbeere-Mix0Erdb
9Jamaica Sun6Jama
10Waldbeeren0Wald
11
12
13
14LOOKUP Table
15Product Name
16Haselnu-Walnu-aromatisiert
17Tiramisu2
18Chocolate-colonial blend
19Chocolate-europe aroma4
20Chocolate-Cookies
21Jamaica Sun6
22Himbeere-Joghurt
23Erdbeere-Quark8
24Erdbeere-Mix
25Banana-Chocolate-Split10
26Waldbeeren
27Kirsche12
28Kirsche-grner Apfel
29Kirsche-Ananas14
30Stracciatella
31Limette-Ksekuchen16
32grner Apfel-Quark
33Blutorange-Quark
Sheet1
Cell Formulas
RangeFormula
B3=VLOOKUP(A3,$A$16:$C$33,3,FALSE)
B4=VLOOKUP(A4,$A$16:$C$33,3,FALSE)
B5=VLOOKUP(A5,$A$16:$C$33,3,FALSE)
B6=VLOOKUP(A6,$A$16:$C$33,3,FALSE)
B7=VLOOKUP(A7,$A$16:$C$33,3,FALSE)
B8=VLOOKUP(A8,$A$16:$C$33,3,FALSE)
B9=VLOOKUP(A9,$A$16:$C$33,3,FALSE)
B10=VLOOKUP(A10,$A$16:$C$33,3,FALSE)
D3=LEFT(A3,4)
D4=LEFT(A4,4)
D5=LEFT(A5,4)
D6=LEFT(A6,4)
D7=LEFT(A7,4)
D8=LEFT(A8,4)
D9=LEFT(A9,4)
D10=LEFT(A10,4)




I apply this code

Code:
[color=darkblue]Sub[/color] Evaluate_Left()[color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range
[color=darkblue]Set[/color] rngName = ThisWorkbook.Worksheets("Sheet1").Range("A3:A10")
[color=darkblue]Dim[/color] rngEE [color=darkblue]As[/color] Range
[color=darkblue]Set[/color] rngEE = ThisWorkbook.Worksheets("sheet1").Range("E3:E10")
[color=darkblue]Let[/color] rngEE = Evaluate("if(row(3:10),LEFT(" & rngName.Address & ",4))")
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_Left()[/color]


And get the following:-


Book1
ABCDE
1Produnt
2Name
3Chocolate-europe aroma4ChocChoc
4Chocolate-Cookies0ChocChoc
5Banana-Chocolate-Split10BanaBana
6Limette-Ksekuchen16LimeLime
7Erdbeere-Quark8ErdbErdb
8Erdbeere-Mix0ErdbErdb
9Jamaica Sun6JamaJama
10Waldbeeren0WaldWald
11
12
Sheet1


Which again is wot I expect.


Now I apply this code

Code:
[color=darkblue]Sub[/color] Evaluate_VLOOKUP()[color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range
[color=darkblue]Set[/color] rngName = ThisWorkbook.Worksheets("Sheet1").Range("A3:A10")
[color=darkblue]Dim[/color] rngCC [color=darkblue]As[/color] Range
[color=darkblue]Set[/color] rngCC = ThisWorkbook.Worksheets("sheet1").Range("C3:C10")
[color=darkblue]Let[/color] rngCC = Evaluate("if(row(3:10),VLOOKUP(" & rngName.Address & ",$A$16:$C$33,3,FALSE))")
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_VLOOKUP()[/color]


…but get the following:-



Book1
ABCDE
1Produnt
2Name
3Chocolate-europe aroma44ChocChoc
4Chocolate-Cookies04ChocChoc
5Banana-Chocolate-Split104BanaBana
6Limette-Ksekuchen164LimeLime
7Erdbeere-Quark84ErdbErdb
8Erdbeere-Mix04ErdbErdb
9Jamaica Sun64JamaJama
10Waldbeeren04WaldWald
11
12
Sheet1


. I would have expected that result without The extra If Row() stuff, which I thought overcame this problem.
. can anyone suggest wot is going wrong, or how I obtain the correct results (Using the Evaluate Function for a range)
Thanks
Alan.

P.s. I will also post this Thread Here: Multiple Columns Into Single Column Using Data Text To Column - Page 2
 
It's the thread that keeps on giving...


Evaluate is limited to a formula length of ca. 255 characters. If you use the External:=True parameter you are including the full workbook name in the formula string, when all you need is the sheet name. That last is why the original didn't work -...........


….OK….. I shortened the name of my external Look Up Table file from “ExternalLookUpTable” to “LUP” as in the modified last code:



Code:
[color=darkblue]Sub[/color] Evaluate_INDEXwithMATCHMegaMegaRoryA6()
 
    [color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range, rngLUpValues [color=darkblue]As[/color] Range, rngLUpEntries [color=darkblue]As[/color] Range, rngLUpOffset [color=darkblue]As[/color] Range
 
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("LUP").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("LUP").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("LUP").Worksheets("LookUpTable").Range("$A$15")
   
    [color=darkblue]Set[/color] rngName = ActiveSheet.Range("$A$3:$A$10")
 
    [color=darkblue]Dim[/color] rngJJ [color=darkblue]As[/color] Range, rngLL [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] rngJJ = ActiveSheet.Range("J3:J10")
    [color=darkblue]Set[/color] rngLL = ActiveSheet.Range("L3:L10")
    [color=darkblue]Let[/color] rngJJ = ""
    [color=darkblue]Let[/color] rngLL = ""
    [color=darkblue]Let[/color] rngJJ.Value = Evaluate("INDEX(INDEX(" & rngLUpValues.Address(External:=True) & ",N(IF(1,MATCH(" & rngName.Address & "," & rngLUpEntries.Address(External:=True) & ",0))),3),)")
 
    [color=darkblue]Let[/color] rngLL.Value = Evaluate("INDEX(INDEX(" & rngLUpValues.Address(External:=True) & ",N(IF(1,MMULT(N(TRANSPOSE(" & rngLUpEntries.Address(External:=True) & ")=" & rngName.Address & "),ROW(" & rngLUpEntries.Address(External:=True) & ")-ROW(" & rngLUpOffset.Address(External:=True) & ")))),3),)")
   
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_INDEXwithMATCHMegaMegaRoryA6()[/color]

…and results….



Book1
ABCJKL
1ProduntRory1Rory2
2NameRange Evaluate INDEX with MATCHRange Evaluate INDEX with MATCH
3Chocolate-europe aroma44
4Chocolate-Cookies
5SCHMELZKSE/WWSPREAD philadelphia 179/15/7,6/4/,1/,5/,4/ kruter 152/11/7,8/4,8/4,6/,7/,5/ leicht110/4,7/11,5/5/5/,4/,4/ kruter 186/15/9/3,7/ / /brlauch 296/28/5/5/3/1/,7/ bresco 230/19,5/8,2/5,4////frischksekruter 186/15/9/3,7/ / / /brunchkraut/gurk 215/20,5/4,2/3,5/3/,1/,45/cleop 220/20/4,5/6/5/,1/,35/ bresco 230/19,5/8,2/5,4////#WERT!10
6Limette-Ksekuchen1616
7Erdbeere-Quark88
8Erdbeere-Mix
9Jamaica Sun66
10#NV
11
12
13
14LOOKUP Table
15Product Name
16Haselnu-Walnu-aromatisiert
17Tiramisu2
18Chocolate-colonial blend
19Chocolate-europe aroma4
20Chocolate-Cookies
21Jamaica Sun6
22Himbeere-Joghurt
23Erdbeere-Quark8
24Erdbeere-Mix
25SCHMELZKSE/WWSPREAD philadelphia 179/15/7,6/4/,1/,5/,4/ kruter 152/11/7,8/4,8/4,6/,7/,5/ leicht110/4,7/11,5/5/5/,4/,4/ kruter 186/15/9/3,7/ / /brlauch 296/28/5/5/3/1/,7/ bresco 230/19,5/8,2/5,4////frischksekruter 186/15/9/3,7/ / / /brunchkraut/gurk 215/20,5/4,2/3,5/3/,1/,45/cleop 220/20/4,5/6/5/,1/,35/ bresco 230/19,5/8,2/5,4////10
26Waldbeeren
27Kirsche12
28Kirsche-grner Apfel
29Kirsche-Ananas14
30Stracciatella
31Limette-Ksekuchen16
32grner Apfel-Quark
33Blutorange-Quark
LookUpValues



:) :) :)

… Somewhere along the lines I had sometihing working like this by triall and error. But thanks to your help I, (and I expect anyone else following this Thread), have an idea why!..
. That makes a big difference (at least to my) sanity!.

Thanks again
Alan Elston.
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
…….
Evaluate is limited to a formula length of ca. 255 characters. If you use the External:=True parameter you are including the full workbook name in the formula string, when all you need is the sheet name. That last is why the original didn't work - Application.Evaluate always evaluates in the context of the active sheet, so if you don't supply sheet references, your ranges all need to be on the same sheet. Worksheet.Evaluate evaluates in the context of the specified sheet whether or not it is active.

……….. one point I had very similar example files to those in this thread working….then my computer just crashed under the strain!
. It may have had something to do with the sheet referencing, - so I will bare your comments in mind……

….my main computer is repaired, so just for anyone following this thread…..

….I am assuming that I must use the External:=True parameter for trying to access an external Look Up Table? ? Any comments to this would be welcome

. That being the case, I have done some extensive tests saving the same Look Up Table File with many different names and sheet names. I share here just a summary.
. The full workbook name is certainly playing a role in getting the two Mega Formulas working.
. For example, going back to my original Example file and playing (changing) with the full File name

… This is about* the limit to get the second Mega formula to work:

Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$15")

. This for example will not work for the second Mega Formula:

Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$15")




( * To tie it down to the exact last character length that will work then as expected you need to increase the length in turn of each file, as I have tediously done!, so for example this will just about work
Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$15")
)



. Similarly, looking at changing the sheet name length:
.. This will not work for the second Mega formula.

Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTableA").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTableA").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTableA").Range("$A$15")

.. but reducing the Workbook names appropriately results in the following working:

Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOP").Worksheets("LookUpTableA").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOP").Worksheets("LookUpTableA").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOP").Worksheets("LookUpTableA").Range("$A$15")


. I achieved eventually a similar limitation in the first mega Formula, but this was a much larger. This is probably as expected as the evaluate formula has fewer references to files.

. …………………………………………………………………………………….
…….
Evaluate is limited to a formula length of ca. 255 characters. ……..
. This possibly needs a bit more thinking about… taking the full file names that just about worked again

Code:
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$15")

But modifying it to give some ridiculously long strings in the evaluate string argument.. gives a code such as this…

Code:
[color=darkblue]Sub[/color] Evaluate_INDEXwithMATCHMegaMegaRoryA6()
 
    [color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range, rngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValues [color=darkblue]As[/color] Range, rngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntries [color=darkblue]As[/color] Range, rngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffset [color=darkblue]As[/color] Range
 
    [color=darkblue]Set[/color] rngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValues = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntries = Workbooks("ABCDEFGHIJKLMNOPQR").Worksheets("LookUpTable").Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffset = Workbooks("ABCDEFGHIJKLMNOPQ").Worksheets("LookUpTable").Range("$A$15")
   
    [color=darkblue]Set[/color] rngName = ActiveSheet.Range("$A$3:$A$10")
 
    [color=darkblue]Dim[/color] rngJJ [color=darkblue]As[/color] Range, rngLL [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] rngJJ = ActiveSheet.Range("J3:J10")
    [color=darkblue]Set[/color] rngLL = ActiveSheet.Range("L3:L10")
    [color=darkblue]Let[/color] rngJJ = ""
    [color=darkblue]Let[/color] rngLL = ""
    [color=darkblue]Let[/color] rngJJ.Value = Evaluate("INDEX(INDEX(" & rngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValues.Address(External:=True) & ",N(IF(1,MATCH(" & rngName.Address & "," & rngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntries.Address(External:=True) & ",0))),3),)")
 
    [color=darkblue]Let[/color] rngLL.Value = Evaluate("INDEX(INDEX(" & rngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValuesrngLUpValues.Address(External:=True) & ",N(IF(1,MMULT(N(TRANSPOSE(" & rngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntries.Address(External:=True) & ")=" & rngName.Address & "),ROW(" & rngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntriesrngLUpEntries.Address(External:=True) & ")-ROW(" & rngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffsetrngLUpOffset.Address(External:=True) & ")))),3),)")
   
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_INDEXwithMATCHMegaMegaRoryA6()[/color]

Which still works!! So clearly what is being talked about by the “Evaluate Formula length” is something subtle and not a simple case of adding the characters in the evaluate string argument!! (I think??)

. To further demonstrate this point…
. This “Windows” version of a code that did work does not work.

Code:
    [color=darkblue]Set[/color] rngLUpValues = Windows("ABCDEFGHIJKLMNOPQ").ActiveSheet.Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Windows("ABCDEFGHIJKLMNOPQ").ActiveSheet.Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Windows("ABCDEFGHIJKLMNOPQ").ActiveSheet.Range("$A$15")

. In order for this to work the File names must be reduced a bit:

Code:
    [color=darkblue]Set[/color] rngLUpValues = Windows("ABCDEFGHIJKLMNOP").ActiveSheet.Range("$A$16:$C$33")
    [color=darkblue]Set[/color] rngLUpEntries = Windows("ABCDEFGHIJKLMNOPQ").ActiveSheet.Range("$A$16:$A$33")
    [color=darkblue]Set[/color] rngLUpOffset = Windows("ABCDEFGHIJKLMNOP").ActiveSheet.Range("$A$15")

(Note: it was found that the External:=True parameter was still needed to make these codes work)


. here is One final code version, for completeness, which includes the Worksheet in the evaluate string argument to make it longer…

Code:
[color=darkblue]Sub[/color] Evaluate_INDEXwithMATCHMegaMegaRoryA7()
 
 
 
    [color=darkblue]Dim[/color] wkstBlc [color=darkblue]As[/color] Worksheet, wkstPro [color=darkblue]As[/color] Worksheet [color=green]'Main File Worksheet, File with entries Worksheet[/color]
    [color=darkblue]Dim[/color] Blanco [color=darkblue]As[/color] [color=darkblue]String[/color], LookUpTable [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Let[/color] Blanco = "VBA Evaluate Range VLOOKUP and INDEX witm MATCH.xlsm"
    [color=darkblue]Set[/color] wkstBlc = Workbooks(Blanco).Worksheets.Item(5) [color=green]'fifth sheet in main File[/color]
    [color=darkblue]Let[/color] LookUpTable = "ABCDEFGHIJKLMNOPQ.xlsx"
    [color=darkblue]Set[/color] wkstPro = Workbooks(LookUpTable).Worksheets("LookUpTable") [color=green]'First sheet in File with entries[/color]
    [color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] rngName = wkstBlc.Range("A3:A10")
   
    [color=darkblue]Dim[/color] lLastRow [color=darkblue]As[/color] [color=darkblue]Long[/color] [color=green]'[/color]
    lLastRow = 10
    [color=darkblue]Dim[/color] rngLL [color=darkblue]As[/color] Range, rngJJ [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] rngLL = wkstBlc.Range("L3:L" & lLastRow)
    [color=darkblue]Set[/color] rngJJ = wkstBlc.Range("J3:J" & lLastRow)
   
 
   
   
    [color=darkblue]Let[/color] rngJJ = ""
    [color=darkblue]Let[/color] rngLL = ""
  
    [color=darkblue]Let[/color] rngJJ.Value = Evaluate("INDEX(INDEX(" & wkstPro.Range("A16:C33").Address(External:=True) & ",N(IF(1,MATCH(" & rngName.Address & "," & wkstPro.Range("A16:A33").Address(External:=True) & ",0))),3),)")
 
 
    [color=darkblue]Let[/color] rngLL.Value = Evaluate("INDEX(INDEX(" & wkstPro.Range("A16:C33").Address(External:=True) & ",N(IF(1,MMULT(N(TRANSPOSE(" & wkstPro.Range("A16:A33").Address(External:=True) & ")=" & rngName.Address & "),ROW(" & wkstPro.Range("A16:A33").Address(External:=True) & ")-ROW(" & wkstPro.Range("A15").Address(External:=True) & ")))),3),)")
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_INDEXwithMATCHMegaMegaRoryA7()[/color]

… was still found to have a similar “ABCDEFGHIJKLMNOPQ” length limitation.

…………………………………………….

Some last puzzling results:

. 1) Note that this last code does not reference the active sheet at all. It references the Look Up Values Workbook. As an experiment I changed The name and path of this workbook to something ridiculously long and there were no differences in the results in the “ABCDEFGHIJKLMNOPQ” length limitation

. 2) Another result noticed.. reducing the Full file name by saving, for example directly on a drive, rather than in various sub folders as I had, did not affect the results. (For completeness I increased the full File name of the “ABCDEFGHIJKLMNOPQ” File to something ridiculous to D:\Ab OKT 2013\YouTube Comments Kontakt GuteFrage Forums\OffenFragens\Excel Beispiel Files\EvaluateCuncatenate\ABCDEFGHIJKLMNOPQRSTUVWXYZ\ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ2 …… and the codes still worked!!)

….. So what is meant here by the “Full Workbook name” is not necessarily the Full File Name” !?



. Enough to be thinking about here for now……


Alan
 
Upvote 0
It doesn't matter how long your variable names are - they are not part of the string passed to Evaluate.
 
Upvote 0
It doesn't matter how long your variable names are - they are not part of the string passed to Evaluate.
….etc:

. An attempt to summaries findings to date:

. 1) Using the External:=True parameter includes the full workbook name (including the string) in the formula string, but exactly what part of the full name is passed is not clear. Clearly the full path name is not used. The workbook and sheet are somewhere taken, but the slight differences noted in referencing workbook with the sheet compared to Windows with Active sheet shows again it is difficult to tie down exactly wot is taken as part of the string passed to Evaluate.

. 2) Variable names are are not part of the string passed to Evaluate.

Another couple just noticed:

. 3) ….. whether I type in a number like 33 or 3644 for my last row in the look Up Table, or instead include
Code:
    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Let[/color] LastRow = 3644 [color=green]'3644 Last Row in Look Up Table[/color]
and replace
Code:
    [color=darkblue]Let[/color] LastRow = 3644" [color=green]'3644[/color]
With
Code:
    [color=darkblue]Set[/color] rngJJ = ActiveSheet.Range("J3:J" & LastRow)
The workbook or worksheet name must not be adjusted.
. … So presumably just the number is passed as part of the string passed to Evaluate.

. 4) As I increased the number of rows above 99 I had to reduce accordingly this
Code:
    Set rngLUpValues = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OPQR[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$C$" & LastRow)
    Set rngLUpEntries = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OPQ[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$A$" & LastRow)
    Set rngLUpOffset = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OPQ[/COLOR]").Worksheets("LookUpTable").Range("$A$15")
To this:
Code:
    Set rngLUpValues = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OPQ[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$C$" & LastRow)
    Set rngLUpEntries = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OP[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$A$" & LastRow)
    Set rngLUpOffset = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OPQ[/COLOR]").Worksheets("LookUpTable").Range("$A$15")
… and similarly as the row number went above 999, I had to reduce further
Code:
    Set rngLUpValues = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OP[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$C$" & LastRow)
    Set rngLUpEntries = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]O[/COLOR]").Worksheets("LookUpTable").Range("$A$16:$A$" & LastRow)
    Set rngLUpOffset = Workbooks("ABCDEFGHIJKLMN[COLOR=#ff0000]OP[/COLOR]").Worksheets("LookUpTable").Range("$A$15")
. ……so I think this shows clearly a direct relationship concluding that the “length” in digits of this number is part of the character sum of the string passed to Evaluate.



…………………………………………………………………………………………………










Hi Rory….


It's the thread that keeps on giving...

….

. I am almost here now on this one. I appreciate it has dragged on a bit and I have had much help to which I am extremely grateful: I am having to work on this when I can as a private project unpaid in isolation (stuck in a very cold part of Bavaria!!) and so am, I guess, sort of developing my project here in this and other Threads in MrExcel. I have tried to give back as much as I can at the moment and the Thread appears well viewed. I am keenly waiting to feedback to some other popular threads for example comparing this Method with others in speed tests etc. But I have now hit on (what I hope is a final major problem) with my actual Files when using your last mega Formula.
. I will adjust and repeat the problem as near I can to follow the simplified example in this Thread. (Possibly it might be appropriate to start a new thread. Or ideally, as a moderator I think you “have the Power” to change the Title to VBA Evaluate Range and VLOOKUP and INDEX with MATCH? – just an idea to do justice to the material here and to assist its finding in searches?)

. So….. The problem. There seems to be a limit in numbers of rows. This limit is somewhat inconsistent changing from time to time for the same Files.!?! But for the example File and my actual Files I am talking about 3000 to 4700. Strangely the number reduces as time goes on, that is to say as you run the code more times!?!?

. Here is an extract from my new Look Up table which I have simply extended to 7000 Rows.


Book1
ABC
13
14LOOKUP Table
15Product Name
16Haselnu-Walnu-aromatisiert
17Tiramisu2
18Chocolate-colonial blend
19Chocolate-europe aroma4
20Chocolate-Cookies
21Jamaica Sun6
22Himbeere-Joghurt
23Erdbeere-Quark8
24Erdbeere-Mix
25SCHMELZKSE/WWSPREAD philadelphia 179/15/7,6/4/,1/,5/,4/ kruter 152/11/7,8/4,8/4,6/,7/,5/ leicht110/4,7/11,5/5/5/,4/,4/ kruter 186/15/9/3,7/ / /brlauch 296/28/5/5/3/1/,7/ bresco 230/19,5/8,2/5,4////frischksekruter 186/15/9/3,7/ / / /brunchkraut/gurk 215/20,5/4,2/3,5/3/,1/,45/cleop 220/20/4,5/6/5/,1/,35/ bresco 230/19,5/8,2/5,4////10
26Waldbeeren
27Kirsche12
28Kirsche-grner Apfel
29Kirsche-Ananas14
30Stracciatella
31Limette-Ksekuchen16
32grner Apfel-Quark
33Blutorange-Quark
34Row34C34
35Row35C35
6999Row6999C6999
7000Row7000C7000
7001
LookUpTableA


File:
https://app.box.com/s/jnjrtpa1saqhu2vb70po

. And Look Up Value Table extract before running any macros


Book1
ABCJKL
1ProduntMega Rory1Mega Rory2
2Name (Look Up Values)Range Evaluate INDEX with MATCHRange Evaluate INDEX with MATCH
3Chocolate-europe aroma
4Chocolate-Cookies
5SCHMELZKSE/WWSPREAD philadelphia 179/15/7,6/4/,1/,5/,4/ kruter 152/11/7,8/4,8/4,6/,7/,5/ leicht110/4,7/11,5/5/5/,4/,4/ kruter 186/15/9/3,7/ / /brlauch 296/28/5/5/3/1/,7/ bresco 230/19,5/8,2/5,4////frischksekruter 186/15/9/3,7/ / / /brunchkraut/gurk 215/20,5/4,2/3,5/3/,1/,45/cleop 220/20/4,5/6/5/,1/,35/ bresco 230/19,5/8,2/5,4////
6Limette-Ksekuchen
7Erdbeere-Quark
8Erdbeere-Mix
9Jamaica Sun
10
36Row36
37Row37
38Row38
39Row39
LookUpValues


. Again after running a macro with rows < 3000


Book1
ABCJKL
1ProduntMega Rory1Mega Rory2
2Name (Look Up Values)Range Evaluate INDEX with MATCHRange Evaluate INDEX with MATCH
3Chocolate-europe aroma44
4Chocolate-Cookies
5SCHMELZKSE/WWSPREAD philadelphia 179/15/7,6/4/,1/,5/,4/ kruter 152/11/7,8/4,8/4,6/,7/,5/ leicht110/4,7/11,5/5/5/,4/,4/ kruter 186/15/9/3,7/ / /brlauch 296/28/5/5/3/1/,7/ bresco 230/19,5/8,2/5,4////frischksekruter 186/15/9/3,7/ / / /brunchkraut/gurk 215/20,5/4,2/3,5/3/,1/,45/cleop 220/20/4,5/6/5/,1/,35/ bresco 230/19,5/8,2/5,4////#WERT!10
6Limette-Ksekuchen1616
7Erdbeere-Quark88
8Erdbeere-Mix
9Jamaica Sun66
10#NV
36Row36C36C36
37Row37C37C37
38Row38C38C38
39Row39C39C39
LookUpValues


. For row numbers typically > 4000 it errors with error 1004, and says something in German roughly translated to “The Element with the given name was not found”
. I appreciate at this point it is all getting somewhat complicated and unclear and I shall be working further when I can very hard to sort this out. But just on the off chance that anything springs to mind as an obvious cause for this row limitation in the last mega formula I would be grateful. Otherwise thanks again for all your help and comments.

Alan.
P.s.

Here is my latest example code version for the last row tests

Code:
[color=darkblue]Sub[/color] Evaluate_INDEXwithMATCHMegaMegaRoryA6()
[color=green]'    On Error GoTo TheEnd[/color]
[color=green]'    Application.ScreenUpdating = False[/color]
[color=green]'    Application.Calculation = xlCalculationManual[/color]
    [color=darkblue]Dim[/color] rngName [color=darkblue]As[/color] Range, rngLUpValues [color=darkblue]As[/color] Range, rngLUpEntries [color=darkblue]As[/color] Range, rngLUpOffset [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Let[/color] LastRow = 3000  [color=green]'Typical Limits Found around: 4668 ; 3644[/color]
 
 
    [color=darkblue]Set[/color] rngLUpValues = Workbooks("ABCDEFGHIJKLMNO").Worksheets("LookUpTable").Range("$A$16:$C$" & LastRow)
    [color=darkblue]Set[/color] rngLUpEntries = Workbooks("ABCDEFGHIJKLMNO").Worksheets("LookUpTable").Range("$A$16:$A$" & LastRow)
    [color=darkblue]Set[/color] rngLUpOffset = Workbooks("ABCDEFGHIJKLMNO").Worksheets("LookUpTable").Range("$A$15")
   
    [color=darkblue]Set[/color] rngName = ActiveSheet.Range("$A$3:$A$" & LastRow)
 
    [color=darkblue]Dim[/color] rngJJ [color=darkblue]As[/color] Range, rngLL [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] rngJJ = ActiveSheet.Range("J3:J" & LastRow)
    [color=darkblue]Set[/color] rngLL = ActiveSheet.Range("L3:L" & LastRow)
    [color=darkblue]Let[/color] rngJJ = ""
    [color=darkblue]Let[/color] rngLL = ""
    [color=darkblue]Let[/color] rngJJ.Value = Evaluate("INDEX(INDEX(" & rngLUpValues.Address(External:=True) & ",N(IF(1,MATCH(" & rngName.Address & "," & rngLUpEntries.Address(External:=True) & ",0))),3),)")
 
    [color=darkblue]Let[/color] rngLL.Value = Evaluate("INDEX(INDEX(" & rngLUpValues.Address(External:=True) & ",N(IF(1,MMULT(N(TRANSPOSE(" & rngLUpEntries.Address(External:=True) & ")=" & rngName.Address & "),ROW(" & rngLUpEntries.Address(External:=True) & ")-ROW(" & rngLUpOffset.Address(External:=True) & ")))),3),)")
TheEnd:
    Application.ScreenUpdating = [color=darkblue]True[/color]
    Application.Calculation = xlCalculationAutomatic
[color=darkblue]End[/color] [color=darkblue]Sub[/color] [color=green]'Evaluate_INDEXwithMATCHMegaMegaRoryA6()[/color]


. It is in Module “ExternalLookUpTableProb “ in this XL2007 .xlsm File:

https://app.box.com/s/olpz5cp7fhn1pjgu297n
 
Upvote 0
There is no limitation on the length of the table. Consistent with the fact that Excel only alphabetizes 255 characters, you're limited to 255-character strings for lookups and match.
 
Upvote 0
There is no limitation on the length of the table......

Hi SHG.
Thanks for that. Every bit helps in trying to narrow down wot is causing my 3000 - 4000 limit. :). So I guess I know at least now that it is not a Look Up Table Row Limit in VLOOKUP or INDEX. Thanks

......Consistent with the fact that Excel only alphabetizes 255 characters, you're limited to 255-character strings for lookups and match.

. I don't quite understand wot that means. But OK, I sort of get that the point that I have a 255 character limit in wot is being “given” to the Evaluate. Just seems to a novice like me to be a bit of trial and error to find wot is contributing and what is not to the final count that must be <=255. Clearly I have shown that it is not a simple adding of characters in the Evaluate Argument string. But my experimenting is good learning and I think I have been able to work out some of the things that add to this sum.
. For now the sticking point is the 3000- 4000 limit thing. RoryA warned that that his last 2 Mega codes were somewhat unmaintainable Shame. I still have a gut feeling mastering these sorts of codes could be very interesting: I had already read and was told that codes such as these were not at all possible. But things like the “coercing” seems to be an art rather than a science. Strange: I thought computing was an exact science!?
. I will keep at it. :banghead:

Alan
 
Upvote 0
Not Evaluate's limit.

You have a table entry with 342 characters; for a lookup to work, it can't be more than 255.
 
Upvote 0
Not Evaluate's limit.

You have a table entry with 342 characters; for a lookup to work, it can't be more than 255.

:confused:...Hmm.... er... OK. - I Guess you are talking about some intimate internal workings?... and as a result of that there are 255 from the 342 "left over" as it were for wot I have available to use in the formula I am typing in. But I still have to guess or do experiments as i did to get at what the Evaluate is taking based on what I write in the String argument.... I think I sort of get it.

. (I assume this is still a seperate issue to my strange problem with the 3000 - 4000 Row limit that I am experiencing?)

. Thanks again for replying. :)
. Alan
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top