Consulting

Results 1 to 4 of 4

Thread: Solved: matching that finds the greatest/least amount

  1. #1
    VBAX Regular Danny's Avatar
    Joined
    Mar 2009
    Posts
    49
    Location

    Solved: matching that finds the greatest/least amount

    I have 2 sheets,
    SHEET1 "Balance":
    has a list of company names in column B and balances for different sales in column D.

    SHEET2 "Payments":
    has a list of company names in column H and payments for different sales in column K.

    I am wanting to do a lookup to pull the payment amounts from sheet2 into sheet1 Column E.

    BUT......
    Companies may appear on both sheets multiple times (usually not more than 3). Meaning that they have mutiple balance amounts and multiple payment amounts, and payments often do not equal the full balance amount (but they are close).
    I am trying to write a code that would match the highest payment amount with the highest balance amount, and so on. A VLOOKUP with 2 criterion can knock out a portion but not much. (wouldn't a unique ID be great !!!!! )

    Anyway, i am starting to ramble, hope this makes some sense.
    The attachment has a third sheet showing the ideal outcome, but any help or ideas would be appretiated. There is a macro in module 1 called calcPMT I have been trying to use (if anyone needs a good laugh).
    I not only use all the brains that I have, but all that I can borrow.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    If you only want the largest amount then simply use the max function in column E of your sheet like this:
    =MAX(Sheet1!A1:A18)
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use these array formulae

    =IF(ISERROR(LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20), 1)),0,
    LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20),1))

    =IF(ISERROR(LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20), 2)),0,
    LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20),2))

    =IF(ISERROR(LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20), 3)),0,
    LARGE(IF(Payments!$H$1:$H$20=Balances!B14,Payments!$K$1:$K$20),3))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular Danny's Avatar
    Joined
    Mar 2009
    Posts
    49
    Location
    xld,
    Sorry it has taken me so long to respond.

    Do i need to enter the formulas above in so that the formula would correspond with the value amount on the "balance" sheet, (the top formula goes with the greatest value on the "balance" sheet, and so on) or is there an easier way to enter these in that i am missing?
    I have played with the formula to where it works but it is kinda a mess:

    =IF(ISERROR(LARGE(IF(Payments!$H$1:$H$20=Balances!B20,Payments!$K$1:$K$20), IF(D20=MIN(IF($B$3:$B$20=B20,$D$3:$D$20,"")),COUNTIF(B:B,B20),IF(D20=MAX(IF ($B$3:$B$20=B20,$D$3:$D$20,"")),1,2)))),0,
    LARGE(IF(Payments!$H$1:$H$20=Balances!B20,Payments!$K$1:$K$20),IF(D20=MIN(I F($B$3:$B$20=B20,$D$3:$D$20,"")),COUNTIF(B:B,B20),IF(D20=MAX(IF($B$3:$B$20= B20,$D$3:$D$20,"")),1,2))))
    I not only use all the brains that I have, but all that I can borrow.

Posting Permissions

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