Consulting

Results 1 to 3 of 3

Thread: Solved: Convert formula to Macro; find closest value and return adjacent values

  1. #1

    Solved: Convert formula to Macro; find closest value and return adjacent values

    Hello
    I have a large file with dates and numbers, I found a formula to extract the closest value and return the adjacent values. But when I injected the formula into my file, it took 1 hour to have a result .
    Is it possible to speed it up the calculation with a macro or to replace the formula by a macro?
    (File included)
    Thanks for your help
    Attached Files Attached Files

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If you sort column A ascending,
    =LOOKUP(E1, $A$1:$A$4000, $A$1:$A$4000) will return the number below the value given.
    =LOOKUP(E1, $A$1:$A$4000, $A$2:$A$4001) will return the number above the value given

    =LOOKUP(E1,$A$1:$A$4000, $B$1:$B$4000)
    =LOOKUP(E1,$A$1:$A$4000, $B$2:$B$4001)

    Will return the matching values from column B.

    I think this formula will do what you want
    =IF((LOOKUP(E1,$A$1:$A$4000, $A$2:$A$4001)-E1)<(E1-LOOKUP(E1,$A$1:$A$4000,$A$1:$A$4000)), LOOKUP(E1,$A$1:$A$4000, $B$2:$B$4001), LOOKUP(E1,$A$1:$A$4000, $B$1:$B$4000))

  3. #3
    Thank you very much, works very good.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •