Solved

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

Posted on 2013-01-20
11
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 22

Expert Comment

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

Expert Comment

by:Harsem
ID: 38800705
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
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,
Michael
MonthyBusinessReview.xlsm
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 5

Expert Comment

by:Harsem
ID: 38803303
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
 

Author Comment

by:mike637
ID: 38803509
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
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?
0
 
LVL 43

Accepted Solution

by:
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.
Copy-of-MonthyBusinessReview-3.xlsm
0
 
LVL 46

Expert Comment

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

0
 

Author Closing Comment

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

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

626 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