+ Reply to Thread
Results 1 to 8 of 8

Can I put a variable row number in an IF function???

  1. #1
    Registered User
    Join Date
    12-20-2017
    Location
    Canada
    MS-Off Ver
    2017
    Posts
    17

    Exclamation Can I put a variable row number in an IF function???

    I'm creating a costing sheet for cocktails with separate sheets labelled "CALCULATOR" and "Liquor" and I am trying to make the CALCULATOR automatically populate certain information from the Liquor sheet. Here is my problem...

    The relevant information on the Liquor sheet is in columns A, the product name, and E, the cost per ounce (E3 = cost per ounce of A3, the same is true for all rows in columns A & E). On the CALCULATOR sheet, I've created a drop-down list of the liquor options (Liquor!A) and I would like the CALCULATOR sheet to automatically populate the cost per ounce section (CALCULATOR!F)when the corresponding alcohol is selected.

    On the CALCULATOR sheet, the simple formula that works for a single row is =IF(D6=Liquor!A3,Liquor!E3) but I can't figure out how to make the row number variable or how to make the row number of E dependant upon and matching that of column A.

    I hope this explanation is comprehensive enough to understand my problem. Any help would be greatly appreciated. Normally I can find answers on google, but this particular search has repeatedly come up empty.
    Last edited by Natejss; 12-20-2017 at 05:35 AM. Reason: I have OCD and the sentence was unfinished

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Can I put a variable row number in an IF function???

    Hi Nate, welcome to the forum. Sounds like you need to use a lookup formula. INDEX/MATCH is the most flexible approach. Something like:
    Please Login or Register  to view this content.
    This looks in LiquorA for the value in D6 ("match"). If found, it returns the corresponding value from LiquorE ("index"). One warning: if D6 value appears more than once in LiquorA, this only finds the FIRST instance. You'll need to add additional criteria in order to differentiate.
    Last edited by leelnich; 12-20-2017 at 01:29 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  3. #3
    Registered User
    Join Date
    12-20-2017
    Location
    Canada
    MS-Off Ver
    2017
    Posts
    17

    Re: Can I put a variable row number in an IF function???

    This was exactly what I needed. It works great. Thank you!

    Your explanation was very helpful too. I think I'll be using INDEX/MATCH quite a bit. The only thing I'm not sure I understand is the functionality of the ",0" before the final close-brackets.

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Can I put a variable row number in an IF function???

    MATCH(lookup_value, lookup_array,[match_type]) The zero is the match_type code:

    0 = exact match. lookup_array may be unsorted.
    1 = approximate match. Finds the largest value less than/equal to. lookup_array must be sorted small to large.
    -1 = approximate match. Finds the smallest value greater than or equal to. lookup_array must be sorted large to small.

    Here's a decent intro to these and other functions: https://exceljet.net/index-and-match

    Also, thank you for the rep! If satisfied, please go to Thread Tools (up top) and mark your thread as SOLVED. Regards - Lee
    Last edited by leelnich; 12-20-2017 at 10:14 AM.

  5. #5
    Registered User
    Join Date
    12-20-2017
    Location
    Canada
    MS-Off Ver
    2017
    Posts
    17

    Re: Can I put a variable row number in an IF function???

    Done and done. Thanks my friend. You truly are a guru extraordinaire.

  6. #6
    Registered User
    Join Date
    12-20-2017
    Location
    Canada
    MS-Off Ver
    2017
    Posts
    17

    Re: Can I put a variable row number in an IF function???

    So, I've adjusted my spreadsheet a little bit. I've changed the necessary column reference numbers, I'm using the same process and the very same formula, but for some reason the it's not functioning the way it had before. I'm really hoping you can take a look and tell me where I've gone wrong.
    Attached Files Attached Files

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Can I put a variable row number in an IF function???

    This is your formula in 'Master Calculator'!E7 :
    Please Login or Register  to view this content.
    The formula is referring to itself, a no-no in Excel known as a circular reference. The value you're trying to match - "Smirnoff 750" - is in cell D7. So change E7 to D7:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-20-2017
    Location
    Canada
    MS-Off Ver
    2017
    Posts
    17

    Re: Can I put a variable row number in an IF function???

    You're my hero.

+ 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. Worksheet function with variable number of parameters
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2016, 10:33 AM
  2. [SOLVED] If err.number... gives expected function or variable in Excel 2016
    By BuZZarD73 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-26-2016, 11:18 AM
  3. [SOLVED] Calculate average of variable number of cells variable number of times
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 10:11 AM
  4. [SOLVED] Function to Sum a number of rows based on a variable
    By mstew9415 in forum Excel General
    Replies: 9
    Last Post: 06-23-2014, 09:43 PM
  5. [SOLVED] Using a variable number of cells in SUM function
    By lucasar in forum Excel General
    Replies: 7
    Last Post: 03-14-2014, 04:14 PM
  6. [SOLVED] using Countif Function: Column number stored in a variable
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2014, 06:58 PM
  7. Hyperlink function fails when using variable row number
    By Balex in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-08-2006, 01:45 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