+ Reply to Thread
Results 1 to 11 of 11

look up the max value in column 2 for a unique values in column 1

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Pittsburgh,USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    look up the max value in column 2 for a unique values in column 1

    I have two columns with Names in column one and in column two are numbers. The names in Column 1 can be repeated. I want to find the highest number in column 2 corresponding to each unique name in column 1 and the lowest number in column 2 corresponding to the unique name in column 1.

    Thanks for your help
    Vivek

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: look up the max value in column 2 for a unique values in column 1

    See my attached sheet for two different methods of accomplishing this.

    Method 1 used Advanced Filter to list just the unique names from the list in column A, then used MAX and MIN array functions (applied with Ctrl+Shift+Enter) to return the highest and lowest values associated with each unique name in the list. Only problem with Advanced Filter is it is not dynamic by default. If the original list changes, the unique list won't change until you run the Advanced Filter>Unique Values again. This can be overcome in VBA, but adds more to the task.

    Method 2 used 2 array (Ctrl+Shift+Enter) formulas:
    In cell H2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In cell H3 and filled down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Then used the same MAX and MIN array formulas as in Method 1.

    Hope it helps! Let me know if you have any questions.

    - Moo
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    Pittsburgh,USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: look up the max value in column 2 for a unique values in column 1

    Thanks for your prompt reply.

    The first method works fine with method 2 your excel sheet gives the unique names list that does not correspond to the max min in the same row is there a way to get the max min in method 2 to correspond to the unique name in column H?.

    Thanks in advance.
    Vivek

  4. #4
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: look up the max value in column 2 for a unique values in column 1

    OOPS! Yes... for the MAX and MIN formulas in columns I and J, change the reference from D2 to H2 (see example below)

    Originally in I2: =MAX(IF($A$2:$A$15=$D2,$B$2:$B$15))
    Change to: =MAX(IF($A$2:$A$15=$H2,$B$2:$B$15))

    Originally in J2: =MIN(IF($A$2:$A$15=$D2,$B$2:$B$15))
    Change to: =MIN(IF($A$2:$A$15=$H2,$B$2:$B$15))

    Hope that helps.

    - Moo

  5. #5
    Registered User
    Join Date
    10-10-2012
    Location
    Pittsburgh,USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: look up the max value in column 2 for a unique values in column 1

    Doing that gives 0 in both max and min columns for all cells in method 2

  6. #6
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: look up the max value in column 2 for a unique values in column 1

    See my modified sheet attached to this post. It works fine here.

    - Moo
    Last edited by Moo the Dog; 11-06-2012 at 03:10 PM. Reason: Added modified/updated sheet

  7. #7
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: look up the max value in column 2 for a unique values in column 1

    Pivot table. See the attached
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: look up the max value in column 2 for a unique values in column 1

    or with an pivot table.

    Just noticed (a pivot table is already suggested by teethless mama).
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  9. #9
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: look up the max value in column 2 for a unique values in column 1

    Pivot table is another good idea, but like Advanced Filter, does not auto update without a little VBA help. Using Teethless Mama's sheet, with the PT, I added the following code to Sheet1's code page:
    Please Login or Register  to view this content.
    With that code added, anytime a cell is changed in column A or B, the pivot table will refresh.

    - Moo

  10. #10
    Registered User
    Join Date
    10-10-2012
    Location
    Pittsburgh,USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: look up the max value in column 2 for a unique values in column 1

    I am just so new to this and pardon me for my ignorance but how do you add this code is there a website for beginners if this is too trivial a question that you could point me to. Thanks

  11. #11
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: look up the max value in column 2 for a unique values in column 1

    If you are using Teethless Mama's file, follow these steps:

    - Right-click on the tab name that says "Sheet1" and select 'View Code'
    - Copy my code from above and paste it into the open area on the right of the code window
    - Press Ctrl+S to save the file. A message box will pop up saying "The following features cannot be saved in macro-free workbooks..."
    - Click the 'NO' button. A Save As dialog box will appear.
    - Give the file a new name, such as Max and Min - VBA
    - Click next to 'Save as Type' and select 'Excel Macro-Enabled Workbook
    - Choose where you want to save it
    - Click Save

    You can now close out the VBA window. Sheet1 will now refresh anytime a cell is changed in column A or B.

    - Moo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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