+ Reply to Thread
Results 1 to 5 of 5

How to highlight the 2 closest values in a list to a given number in Google Sheets?

  1. #1
    Registered User
    Join Date
    12-14-2023
    Location
    Denmark
    MS-Off Ver
    Google Sheets
    Posts
    3

    How to highlight the 2 closest values in a list to a given number in Google Sheets?

    Hi all,

    I want to highlight the 2 closest values in a list to a given number in Google Sheets. I've found the solution for Excel, but I can't make it work in Google Sheets. Also, my list is horizontal, not vertical.

    extendoffice.com/documents/excel/4095-excel-highlight-closest-value.html

    If you want to highlight the closest 3 values to the given values, you can apply this formula in the Conditional Formatting, =ISNUMBER(MATCH(ABS($D$2-A2),SMALL(ABS($D$2-$A$2:$A$15),ROW($1:$3)),0))
    I've created a sheet for you to look at: docs.google.com/spreadsheets/d/1k4VHPGrmXWcPN_kRCS25ZRy6NIe5w0jjxmAokKlP8c4/edit?usp=sharing

    Do you know if it's possible?

    Thank you!

  2. #2
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: How to highlight the 2 closest values in a list to a given number in Google Sheets?

    Hi delle,

    Thank you for sharing the method, and sample file, they helped make the working solution.

    To get the formula working in Google Sheets, it just needs to be wrapped in ARRAYFORMULA().

    Here is the final solution (see your file for example):

    Please Login or Register  to view this content.
    As a gesture off appreciation, you can click * Add Reputation at the foot of any of the posts of members who helped you reach a solution.

    And finally, was your problem solved? if so, please click Thread Tools above the first post of your enquiry, then select [Solved]

  3. #3
    Registered User
    Join Date
    12-14-2023
    Location
    Denmark
    MS-Off Ver
    Google Sheets
    Posts
    3

    Re: How to highlight the 2 closest values in a list to a given number in Google Sheets?

    Thank you so much. Works flawlessly. Rep added.

    May I ask why wrapping in ARRAYFORMULA() makes all the difference?

  4. #4
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: How to highlight the 2 closest values in a list to a given number in Google Sheets?

    ARRAYFORMULA is required when checking multiple values such as the $B$6:$Z$6

    For older versions of Excel, the solution for dealing with arrays is to wrap the formula in {curly brackets}

    The formula in the article does not mention that, perhaps because it is expected that users of older versions of Excel would already know about that.

    Heres another example... lets say you have an XLSX file with many complicated formulas, if you upload and convert that file to Google Sheets, it is possible that one or more formulas may be wrapped in =ARRAY_CONSTRAIN(ARRAYFORMULA())
    This is Google Sheets recognising the formula is an array type, and it makes the necessary change.
    HOWEVER, the outer ARRAY_CONSTRAIN is almost never needed (i can recall ONE time it was required), so it can be removed, just leaving the ARRAYFORMULA()

    Whenever trying to get an Excel formula working in Google Sheets, if it doesnt work straight away then a good first step in troubleshooting it is to try wrapping the formula in ARRAYFORMULA().

  5. #5
    Registered User
    Join Date
    12-14-2023
    Location
    Denmark
    MS-Off Ver
    Google Sheets
    Posts
    3

    Re: How to highlight the 2 closest values in a list to a given number in Google Sheets?

    Thank you!

+ 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] Google Sheets Select Number From List Excluding Another List
    By Mrlofty in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 10
    Last Post: 05-30-2021, 03:15 AM
  2. Replies: 10
    Last Post: 05-30-2021, 03:15 AM
  3. [SOLVED] Google Sheets - Generating a Sequential list based on previous values
    By lalalalalala in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 9
    Last Post: 12-13-2019, 07:05 AM
  4. [SOLVED] Retrieving the Closest Larger / Closest Smaller Values from a List
    By ChipsSlave in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-31-2017, 08:38 AM
  5. [SOLVED] get 10 Closest Larger / Closest Smaller Values from a List
    By Auni in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 04:07 AM
  6. use vba to highlight closest number match
    By Toidz77 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2009, 12:55 PM
  7. Replies: 0
    Last Post: 08-25-2005, 02:37 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