+ Reply to Thread
Results 1 to 12 of 12

Can you use VLOOKUP to Return a Formula Instead of a Value?

  1. #1
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Can you use VLOOKUP to Return a Formula Instead of a Value?

    Hi All,

    I have a very long nested IF function calculating elapsed time relative to certain criteria. The formula works well until the criteria is changed and I have to rewrite the entire formula (some 50 statements).

    I’m looking for alternatives and thought of VLOOKUP using a data table containing the formulas with the criteria as the lookup values. I have played around with VLOOKUP and it will return the formula, however, the formula is relative to the original position it was created as i.e. if my formula is SITE 1 = A2 + B2, should SITE 1 appear in row 50 the formula still returns A2 + B2

    Is it even possible to Lookup a formula rather than a value? If so, how? I have added a small VBA code to apply Formulatext and can expand the formula as text (am using 2010) but still have trouble applying the formula relative to its position.

    If not, is there a more efficient or alternative way to create many IF statements?

    Attached is an example of some of the formulas I have nested into an IF Statement, ideally would want to create a table with the hours of operation as the look up value and for it return and apply the formula.

    Thanks for your help
    Attached Files Attached Files
    Last edited by Puni; 09-14-2015 at 04:47 PM. Reason: Added Attachment

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,261

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    In order to ascertain whether or not your IF statements can be replaced it would help if you can post a sample file with examples of what is required.

    A 50 statement formula sounds horrendous!

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    The formula being returned is actually a text string that looks like a formula. You would need to EVALUATE that string as if it were a formula (assuming you could change the row to reflect the one that the formula is on), but you can only do that using a UDF, as there is no EVALUATE function within standard Excel functions (it is available in VBA). If you are going to need a UDF, then you might as well incorporate all the functions of the long formula within it.

    I suggest you post this massive nested-IF formula and explain what it is trying to do, then we might be able to suggest a suitable alternative.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    Hi,

    Whoa, you guys are quick! Many thanks, have edited and attached a sample of the formulas. The formula itself is fairly long and when you nest it it becomes massive..

    Thanks,

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,261

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    No IF statement present: only one SUMPRODUCT. Which column/Cell?

  6. #6
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    Hi,

    I have attached another version of the example workbook. The "Data" worksheet contains examples of the incident duration I calculate. For ease of example I have cut down the IF statement - the IF statement is performed in col F and is based on the criteria in col B - "Hours of Operation", depending on what the site hours are the SUMPRODUCT will start and stop the timer etc.

    The IF formula as it is works fine, the issue is when the customer decides to change the hours of operation and I have to rewrite the long nested formula to accommodate.

    The "Formulas" worksheet is my attempt to build a look up table where I can add maintain all the different hours of operation with the relevent formula calculation - col F and, if possible, perform a VLOOKUP against Col F using the "Hours of Operation" from col B in the data worksheet as the lookup value.

    The problem arises as the formulas in col F are relative to its position from the data table the formulas are pulled from and not where it returns the result in the "data" worksheet.

    Sorry, I hope that is a bit clearer.

    Thanks,
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    I don't have XL2010+ so I can't test NETWORKDAYS.INTL, yet.

    On sheet DATA, column G, your VLOOKUP is returning the values from sheet FORMULAS column F (Down time). Should that be col G (6) instead (the formula text)?

    On sheets formula, the function is returning the formulas used in column F with the cell addresses hard coded. You might try R1C1 references.
    Please Login or Register  to view this content.
    * After the formulas are returned you must copy/paste values.
    Last edited by protonLeah; 09-20-2015 at 11:25 PM.
    Ben Van Johnson

  8. #8
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    Hi ProtonLeah,

    Many thanks for your help. I'm not sure I followed your instructions correctly but I edited the existing VB script to read as per your above code. I changed the Excel settings to use R1C1 reference style and then performed the VLOOKUP using the hours of operation in the "Data" sheet Col 2 as the look up value, returning the formula from the "Formulas" sheet col 7 - Formula Text. This populates the col 7 VLOOKUP Attempt in the "Data" sheet with the formula, however, I seem to progress no further. I have copied and pasted the formulas from col 7 but it retains the formula only and not the value. I have attached my workings in the "Hours of Operation with IF Statement_v2" workbook. Any idea on where I may be going wrong?

    Thanks,
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    I added a new function "TimeCalc" to evaluate the lookup formula:
    Please Login or Register  to view this content.
    restructured the formula sheet two columns after extraction the formulaR1C1 text strings

    moved the values only, of the massive IF formulas in column F of the data sheet to column G just to verify the results of the new VLookUp formulas

    replaced the original massive formulas in column F with:

    Please Login or Register  to view this content.
    The only ones I can verify are the ones without the new Netw..Intl function, i.e., "N-S (00:00 - 23:59)" ---> they do check out

  10. #10
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    Thanks ProtonLeah,

    When I open the attachment, the formula calculation in Col F (col 6) returns #VALUE error for the sites other than those with coverage hour “N-S (00:00 - 23:59)”. I assumed as I was using Excel 2010 the formula “NETWORKDAYS.INTL” would calculate and the VLOOKUP would update the cell, however, the cells remains as #VALUE.

    In the scenario I used your workbook as the master to perform my daily calculations and imported my raw data into columns 1 to 4, should the result in col 6 automatically update or are there some additional steps I’m required to perform?

    I played around with the start and end times for sites with hours of operation “N-S (00:00 - 23:59)” and changed the times to see if the result would change in col 6, col 6 didn’t update and I figure I’m doing something wrong or am missing step.

    Any ideas?

    Thanks for all your help

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    I'm sorry, but I could only get the sheet to update/calculate by selecting the cells in column F hitting Enter from the formula bar.

  12. #12
    Registered User
    Join Date
    03-19-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Can you use VLOOKUP to Return a Formula Instead of a Value?

    Hi ProtonLeah, no problem, thank you for assistance, appreciate it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VLookUP or other formula to count and return a value
    By SVTF in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-24-2014, 12:07 PM
  2. H or Vlookup formula to return value
    By Learner1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2014, 07:20 PM
  3. [SOLVED] Formula to always return cell below what a vlookup would return
    By KCHEXCEL in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-28-2013, 12:57 AM
  4. How do I return a formula using vlookup?
    By 288enzo in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-31-2013, 03:22 AM
  5. Vlookup with Max Return formula
    By hydraonstimpac in forum Excel General
    Replies: 10
    Last Post: 02-10-2012, 02:48 AM
  6. Vlookup Formula does not return value
    By dcraker in forum Excel General
    Replies: 8
    Last Post: 04-14-2008, 01:42 PM
  7. [SOLVED] [VBA] how can a Vlookup return the Formula instead of the Value?
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2006, 12:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1