Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2013-01-20
Medium Priority
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,
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 2000 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 46

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

972 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