+ Reply to Thread
Results 1 to 6 of 6

Replacing missing values with nearest known

  1. #1
    Registered User
    Join Date
    01-31-2016
    Location
    The Netherlands
    MS-Off Ver
    MAC 16.18 2018
    Posts
    35

    Replacing missing values with nearest known

    Hello,

    I am trying to find a formula to replace missing values. Please find attached a document for illustrative purposes.

    Sheet1 is the original data sheet, in Sheet2 I would like to have the same values as Sheet1 but replace the BLANK or 0 cells with the nearest known value in the column.

    Any ideas? Thank you
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Replacing missing values with nearest known

    Please define nearest value. Nearest to what?

    Manually add some typical results and explain how you have arrived at them.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Replacing missing values with nearest known

    How do you define nearest known value?

    Take from above, take from below, average of both, something else entirely?

  4. #4
    Registered User
    Join Date
    01-31-2016
    Location
    The Netherlands
    MS-Off Ver
    MAC 16.18 2018
    Posts
    35

    Re: Replacing missing values with nearest known

    Yes, if you look at the document, when the value is missing in the second row it should look from row 3 onwards for the nearest known value; when it is missing in row 30 it should look back at 29 or even further; when it is missing somewhere in between row 3 and 30 it should choose the nearest value above or below, when both are the same distance it should choose the one above.

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Replacing missing values with nearest known

    Try:

    =IF(Sheet1!A2>0,Sheet1!A2,
    IF(ROW(Sheet1!A2)=2,Sheet1!A3,
    IF(AND(Sheet1!A3=0,Sheet1!A1>0),Sheet1!A1,
    IF(ROW(Sheet1!A2)-LOOKUP(10^10,ROW(Sheet1!A$1:A1)/(Sheet1!A$1:A1>0))<=MATCH(TRUE,INDEX(Sheet1!A3:A$31>0,0),0),
    LOOKUP(10^10,Sheet1!A$1:A1/(Sheet1!A$1:A1>0)),INDEX(Sheet1!A3:A$31,MATCH(TRUE,INDEX(Sheet1!A3:A$31>0,0),0))))))

  6. #6
    Registered User
    Join Date
    01-31-2016
    Location
    The Netherlands
    MS-Off Ver
    MAC 16.18 2018
    Posts
    35

    Re: Replacing missing values with nearest known

    Thank you, this works for me. The only issue might be in cases when there are multiple rows at the begging or end (e.g. A2:A3 | A29:A30) with missing values

+ 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. Replacing values from a Cell by Reference values
    By NewBieMSXL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2018, 07:49 AM
  2. VLOOKUP, Descending Dates w/missing, Need Nearest Smaller
    By mot in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 10-28-2015, 12:20 PM
  3. [SOLVED] Replacing formula values with text/raw values
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2013, 12:36 PM
  4. Excel 2007 : Rounding values up to nearest 10p
    By dave_1 in forum Excel General
    Replies: 5
    Last Post: 11-13-2010, 03:54 AM
  5. [SOLVED] How to round values to the nearest 1000?
    By AA Arens in forum Excel General
    Replies: 5
    Last Post: 07-14-2006, 01:45 PM
  6. [SOLVED] Replacing Linked Cell Values w/ Current Values
    By TomCat in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-10-2006, 07:25 AM
  7. [SOLVED] Replacing missing values?
    By Robert Lundqvist in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-28-2006, 04:10 AM

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