Excel VB - Find the 2 highest values and the 2 lowest in column range

Posted on 2013-01-20
Last Modified: 2013-01-24
Hello  Experts,

Once I again I need to turn to you for assistance.

I have data in columns that I need to find the 2 highest numbers and the 2 lowest numbers in each column range. (Max & Min).  

My columns used are "B" to "W" with rows "3:13" being the consistent range.

Once I have found these 4 cells (the 2 max and 2 min) - I will copy them to another worksheet. In addition to this, I need to transfer the corresponding cell from column "A" (same Row) to the other worksheet, as well.  For example: checking Column "D" - the max is in Row 8, Then value of "D8" is Max1 and "A8" is the relating cell.

If the routine put the 4 cells in the corresponding column on lines 15:19, with the offset from column "A" for each entry, then I can copy from there then clear the cells.

Any assistance would be greatly appreciated,
Question by:mike637
  • 3
  • 2
  • 2
  • +2
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 38799998
do you have any code?

Expert Comment

ID: 38800705

Can i ask a couple of contingent questions:

- What if you have the same MAX value in 3 fields (say F4, G7 & W11) which values from Column will be chosen?
- The same as above for min

As for finding those values, you can use a simple formula:


You can see what that gives you, then you can do a max for each line, do a vlookup for that line and get the corresponding value from column A.

I have attached a small example. Rather than doing a VB Script you can have formulas on the other sheet or section of the spreadsheet for you.

I like staying away from Macros as they do not update when cell references change and can be cumbersome to to keep current. Please let me know if you want the attached to be changed to a VB Script, but other than that I hope you can see what I ahve done to achieve the task you are after.


Author Comment

ID: 38801176
Hello Experts,
I am attaching my workbook to assist in coming up with the routine that will handle all these steps.

I put my notes on the sheet "KEY DATA_COPY".  I prefer to keep this in a routine since it is a lot of calculations - since each column from "C:X" needs to be calculated.

I put in the =max function on the worksheet to show what I need from Column C, but then I need the next max figure after that. Which I do not know how to do that.  I also put where I am copying the data to in the previous worksheet.  It will always be the previous worksheet as Months get added, it will always go to the most current month.

I hope this helps to explain what I need to do here.

Thank you,
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.


Expert Comment

ID: 38803303

I have updated your sheet with the large & small functions in the right place.

I think that is what you were after. Please let me know if it was not.


Author Comment

ID: 38803509

This is a start in getting the 2 highest and 2 lowest values.  What I need to do is get the column offset value for these numbers.  If column C then -2, D would be -3 etc.

I would really like to create this into a routine so after all data is either keyed or copied by a routine into the wsheet"KEY DATA_COPY" - that it is copied to the correct cells in the previous worksheet. (the first sheet to the left of the sourcesheet).  I listed a few examples of the destination cells.

This is the complicated piece of finding the offset value for each of the 4 column values. And do this until column "X" is reached.  Then copy data to a varibly named worksheet that is directly prior to the soucesheet.

LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38814398
I have already posted a solution in your other question which is essentially the same as this question. Which question do you want to keep?
LVL 43

Accepted Solution

Saqib Husain, Syed earned 500 total points
ID: 38814418
I am reproducing the solution here. If it works then make sure you delete one of the questions instead of duplicating it.
LVL 45

Expert Comment

ID: 38814429
I don't see any values in columns B and W, do you mean columns C and X?

I would think the simplest, perhaps the most efficient, approach would be to do a sort before each data copy operation
activesheet.range("C3:X11").sort key1:=cells(1,3), order1:=xlAscending, header:=false
'Min1 is in C3
'Min2 is in C4
'Max1 is in C11
'Max2 is in C10
activesheet.range("C3:X11").sort key1:=cells(1,24), order1:=xlAscending, header:=false
'Min1 is in X3
'Min2 is in X4
'Max1 is in X11
'Max2 is in X10

Open in new window


Author Closing Comment

ID: 38814818
This works perfectly.   I think that the only thing I need to do is modify the code to transfers figures to the previous sheet - since more monthly sheets will be added as the year progresses.

Thanks again.

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question