+ Reply to Thread
Results 1 to 6 of 6

Retrieve Value of Last Non-Empty Cell in a range prior to given value

  1. #1
    Registered User
    Join Date
    10-18-2019
    Location
    USA
    MS-Off Ver
    2013 Pro Plus
    Posts
    3

    Retrieve Value of Last Non-Empty Cell in a range prior to given value

    Hi All,

    I am trying to create a form that updates its values dynamically based on a user-entered date. This form pulls data from a range in another sheet that have dates entered as the column headings, like so:

    8/1/2019 9/1/2019 10/1/2019 11/1/2019 12/1/2019 1/1/2020
    85 75 100
    1000 1500 2000 2500
    300 500 600

    So what I am trying to do, is take a given date (I'm going to use 11/1/2019 in this example) and return the value in a specific row under that date. Easy HLOOKUP function, no problem. However, if there is no entry for that date in my table, what I want to do is pull the last non-blank cell in the row prior to the column that corresponds to the target date. Using the above table, what I would am trying to do would result in:


    Target Date 11/1/2019
    Value Date of Entry
    100 10/1/2019
    1500 10/1/2019
    500 11/1/2019

    Where target date is a user-entered value. So if I change the target date to 12/1/2019, the values would update to 100, 2000, and 600. What I have so far is an IF statement that first runs HLOOKUP to see if there is a value in the proper row for the target date, returns it if true, and if false it grabs the last non-empty cell in the row:
    =IF(HLOOKUP(B1,Sheet1!A1:F4,2,FALSE),HLOOKUP(B1,Sheet1!A1:F4,2,FALSE),INDEX(Sheet1!A1:F4,MATCH(9.99E+307,Sheet1!A1:F4))

    That probably looks like a mess, but it does almost everything I want it to do. The problem is created by rows that have values *after* the target date - my index/match function uses the entire table as its array, so it doesn't know when to stop and returns values too far down the table. How do I adjust this function so that it only looks for values in the range A:{column indicated by target date}?

    Thanks everybody!

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

    Re: Retrieve Value of Last Non-Empty Cell in a range prior to given value

    I think what you are saying is that you want to change the F4 which occurs twice in the INDEX/MATCH function needs to be dynamic to respond to the user-entered date. You can do that using INDIRECT or another INDEX function.

    It's difficult to give you an exact formula to try, as I suspect from the formula that you quoted that the two tables are on different sheets, so it would help if you attached a sample Excel workbook.

    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

    Don't try to use the Paperclip icon, as it doesn't work on this forum.

    Hope this helps.

    Pete

    Pete

  3. #3
    Registered User
    Join Date
    10-18-2019
    Location
    USA
    MS-Off Ver
    2013 Pro Plus
    Posts
    3

    Re: Retrieve Value of Last Non-Empty Cell in a range prior to given value

    Hi Pete,

    Thanks for taking a look for me. My test workbook should be attached. I am starting to wonder if it would be easier to find the appropriate range first and then grab the last value in that range, rather than the if statement I have going now. Not yet concerned about the date of entry fields that I have left blank on Sheet2, I should be able to work that out once the values are pulling correctly.

    Thanks again!

    Aki

    edit: fixed some inconsistencies with my formulas
    Attached Files Attached Files
    Last edited by akihiko; 10-18-2019 at 04:50 PM.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,562

    Re: Retrieve Value of Last Non-Empty Cell in a range prior to given value

    Try pasting the following formula into cell A3 on sheet 2 and then copying down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    10-18-2019
    Location
    USA
    MS-Off Ver
    2013 Pro Plus
    Posts
    3

    Re: Retrieve Value of Last Non-Empty Cell in a range prior to given value

    Thank you!! I was finally able to circle back around to this and have it working exactly as desired. I really appreciate the help!

    Just out of curiosity, what exactly is happening in the LARGE function? Why is the column row divided over itself and then again over the target row?

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,562

    Re: Retrieve Value of Last Non-Empty Cell in a range prior to given value

    You're Welcome. As to the LARGE function the first time the range is used (inside the COLUMN function) is to make an array of numbers, the second time is to find only dates on or after the target date (cell B1) and the third time is to omit blanks in the particular row. I'd suggest selecting A4 and using the Evaluate Formula feature to get a better idea of how the formula works.
    Please take a moment to mark the thread as 'Solved' using the thread tools menu above your first post. I hope that you have a blessed day.

+ 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] Using macro to find first empty cell in column. If range is empty returns error.
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-23-2019, 11:03 AM
  2. [SOLVED] Dynamic formula which compares a cell to a prior range of cells
    By nathanwlee in forum Excel General
    Replies: 6
    Last Post: 03-12-2019, 01:22 PM
  3. [SOLVED] Retrieve Code From Prior Term Based on ID
    By Dord25 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 05-31-2018, 02:19 AM
  4. [SOLVED] How to create a dynamic range if the last cell is empty and the columns have empty cells
    By peter_swe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2016, 11:18 PM
  5. Replies: 0
    Last Post: 08-03-2016, 07:01 PM
  6. MACRO to empty a range of cells based on whether specified cell is empty
    By TBJV in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 10:35 PM
  7. Retrieve cell based on first non-empty cell in a row
    By DNADOC in forum Excel General
    Replies: 10
    Last Post: 08-16-2011, 04:53 PM

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