Hello all;
I am a fairly experienced VBA programmer but this is just kicking my backside. I'm trying to lookup a single row in a sheet/table to return a single value based on the values of 5 variables (Yep, it takes 5 pieces of data to isolate a unique row and yes I've preached DATABASE for this project from the very beginning but have been shot down so....).
I can use the =INDEX(....MATCH(1 ,.....,....),0) method in a cell and get an answer. For those of you unfamiliar this rendition of MATCH it uses an array formula as the second argument and returns the product of a number of comparisons (eg. when it finds a row in the table that matches all 5 variables it matches the number 1 that we're looking for and returns the row which is then fed into INDEX. The problem is this now becomes an array formula and I can't get it to execute in VBA. All my attempts either fail to compile or when executed gets me a Type Mismatch error because of the array formula.
I don't want to leave that formula in a cell. This is a massive sheet in an even more massive workbook and recalculating 10,000+ formulas every time you change a single cell value takes forever. I'm using VBA code to determine the correct values and just plopping them in their cells. These values change maybe twice a year so they can just run the code when new data comes in and then get on with their work when it's done running. Alas, nothing I've tried works.
I've come down to breaking this down and putting my MATCH call into a string variable and using the EVALUATE function in VBA. The idea was to get the row number separately and then execute an INDEX function but I can't get past MATCH. The code snippet is as follows:
strEvaluate = "Match(1, (rngYear = intYr) * (rngTech = strTech) * (rngOldModel = arrSchedulerRoles(3, z)) * (rngReplace = strReplace) , 0)"
If Not IsError(varPos = Application.Evaluate(strEvaluate)) Then .....
The rng variables are, as their prefix indicates, Range objects set on the columns of the table we're trying to match to. Each criteria will return a 0 or 1 depending on whether it's true or false. Those criteria are multiplied together to produce an ultimate 0 or 1 product for all criteria. The row that comes back with a 1 for all criteria is the one I'm looking for and is passed back by MATCH. Like I said, the trouble is the Array Formula is causing a Mismatch error.
Has anybody done this before in VBA? If so, I could use some help.
Thank you in advance one and all.....
I am a fairly experienced VBA programmer but this is just kicking my backside. I'm trying to lookup a single row in a sheet/table to return a single value based on the values of 5 variables (Yep, it takes 5 pieces of data to isolate a unique row and yes I've preached DATABASE for this project from the very beginning but have been shot down so....).
I can use the =INDEX(....MATCH(1 ,.....,....),0) method in a cell and get an answer. For those of you unfamiliar this rendition of MATCH it uses an array formula as the second argument and returns the product of a number of comparisons (eg. when it finds a row in the table that matches all 5 variables it matches the number 1 that we're looking for and returns the row which is then fed into INDEX. The problem is this now becomes an array formula and I can't get it to execute in VBA. All my attempts either fail to compile or when executed gets me a Type Mismatch error because of the array formula.
I don't want to leave that formula in a cell. This is a massive sheet in an even more massive workbook and recalculating 10,000+ formulas every time you change a single cell value takes forever. I'm using VBA code to determine the correct values and just plopping them in their cells. These values change maybe twice a year so they can just run the code when new data comes in and then get on with their work when it's done running. Alas, nothing I've tried works.
I've come down to breaking this down and putting my MATCH call into a string variable and using the EVALUATE function in VBA. The idea was to get the row number separately and then execute an INDEX function but I can't get past MATCH. The code snippet is as follows:
strEvaluate = "Match(1, (rngYear = intYr) * (rngTech = strTech) * (rngOldModel = arrSchedulerRoles(3, z)) * (rngReplace = strReplace) , 0)"
If Not IsError(varPos = Application.Evaluate(strEvaluate)) Then .....
The rng variables are, as their prefix indicates, Range objects set on the columns of the table we're trying to match to. Each criteria will return a 0 or 1 depending on whether it's true or false. Those criteria are multiplied together to produce an ultimate 0 or 1 product for all criteria. The row that comes back with a 1 for all criteria is the one I'm looking for and is passed back by MATCH. Like I said, the trouble is the Array Formula is causing a Mismatch error.
Has anybody done this before in VBA? If so, I could use some help.
Thank you in advance one and all.....