Solved

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

Posted on 2013-01-20
11
521 Views
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,
Michael
0
Comment
Question by:mike637
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
do you have any code?
0
 
LVL 5

Expert Comment

by:Harsem
Comment Utility
Hello,

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:

=large(B3:W13,1)
=large(B3:W13,2)
=small(B3:W13,1)
=small(B3:W13,2)

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.

Jens
Sample.xls
0
 

Author Comment

by:mike637
Comment Utility
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,
Michael
MonthyBusinessReview.xlsm
0
 
LVL 5

Expert Comment

by:Harsem
Comment Utility
Hello,

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.

Jens
MonthyBusinessReview.xlsm
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mike637
Comment Utility
Hello,

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.

Michael
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
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?
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
Comment Utility
I am reproducing the solution here. If it works then make sure you delete one of the questions instead of duplicating it.
Copy-of-MonthyBusinessReview-3.xlsm
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
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

0
 

Author Closing Comment

by:mike637
Comment Utility
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now