+ Reply to Thread
Results 1 to 12 of 12

Function to search a list (unsorted) and find location of a value close to a specified var

  1. #1
    Registered User
    Join Date
    04-01-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    5

    Function to search a list (unsorted) and find location of a value close to a specified var

    Here is what I am trying to do.
    I have a list of numerical data taken from a measurement that is not sorted and can't be sorted. Here is the reason why. The values start near 0 then increase up to a max number then decrease back down to zero and do the same thing on the negative end of things. I have to find a point on the increasing positive side (e.g. 2000) and then that same point on the decreasing positive side. The number it finds just needs to be the closest match to the number we are looking for.

    The same thing needs to be done on the negative side as well.

    Below is an example of two points that would be on the curve. Think of the max in the upper right where the two lines meet being ~10000 and the arrows being at a value close to the variable we are looking for (2000).

    Any help would be appreciated

    hysteresis.gif

  2. #2
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Post an example spreadsheet with de-sensitized data. Sounds like a simple lookup question but hard to tell. B is 2000? B is user input ? You are trying to return both positive and negative H that is as near 2000 as possible?
    Please consider adding a * if I helped.

  3. #3
    Registered User
    Join Date
    04-01-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Quote Originally Posted by Brendan_Floyde View Post
    Post an example spreadsheet with de-sensitized data. Sounds like a simple lookup question but hard to tell. B is 2000? B is user input ? You are trying to return both positive and negative H that is as near 2000 as possible?
    Please see the attached. if variable is B then in this case B is 2000 and the peak is 10000. So we need to return the cell position where we see +B on the increasing side to 10000 and where we see +B on the decreasing side from 10000. The two points with arrow are what I want to find the cell location for.

    As you can see, we don't exactly see a value of 2000 but only values that are close. The closest value is the one I would like to find

    Workbook1.xlsx

  4. #4
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    See attached.

    Array formulas. The second result may not be fool proof if you have 2 very close numbers to result 1 but should be good enough.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Change the result 2 formula to this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Far more resilient - then only returns numbers after the climax of the graph

  6. #6
    Registered User
    Join Date
    04-01-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Thanks for the help. One thing about this is that I want to put this into a VBA macro so that I can get row numbers out of it and use another column (not listed) to calculate further information

  7. #7
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Ahh got ya - a lot easier in VBA. One moment .....................

  8. #8
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    below gives you the 2 ranges

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-01-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Thanks for the help. I am still trying to figure out exactly how the code works for this but I appreciate it.

    Could you also help me with the further operation of this? The values also go in the negative direction as well in a similar form. They start as negative numbers near zero then decrease to a min negative number ~ -10000 then increase back to zero

  10. #10
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    Can you update the posted file with perhaps a couple of examples?

    Will a given data range either be postitive B or negative B ..... in which case can probably do something with ABS function or
    Will a given range have both negative and positive B ....... in which case more code!

    ta
    bren

  11. #11
    Registered User
    Join Date
    04-01-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    See the attached for a more realistic data set. FYI the max we will use is typically a fixed value (10500) or (-10500) and looking for a value (2000) or (-2000)

    workBook1.xlsx

  12. #12
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Function to search a list (unsorted) and find location of a value close to a specified

    You could probably make this smaller by banging some of the loops together and using abs() but I prefer long code that is more explicit


    Please Login or Register  to view this content.

+ 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] Find AVERAGE of another column of unsorted list (using INDEX/MATCH ?)
    By seaottr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-06-2013, 10:24 PM
  2. Find the address of an n't max value in an unsorted list
    By bormar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2012, 07:39 PM
  3. Search, find and add the result in a specific location
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2011, 10:42 AM
  4. search and match an unsorted list
    By Venka in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-14-2008, 03:11 AM
  5. Find 7th largest and smallest element in unsorted list
    By cpadude in forum Excel General
    Replies: 2
    Last Post: 06-24-2008, 05:22 PM

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