How to display a value of a cell using the LARGE formula feature - vba

In Excel using the LARGE function I have listed the top five values in the range of cells C2:C13 into the cells F2,F3,F4,F5,F6. I used the following formulas in the corresponding cells to do so:
Cell F2 I used this =LARGE(C2:C13,1)
Cell F3 I used this =LARGE(C2:C13,2)
Cell F4 I used this =LARGE(C2:C13,3)
Cell F5 I used this =LARGE(C2:C13,4)
Cell F6 I used this =LARGE(C2:C13,5)
Here is a screenshot:
However, what I would like to do is to display the value of the cells to the left of the five greatest values. Below is a screenshot of how I would like it to work if possible:

Please try:
=INDEX(B:B,MATCH(LARGE(C$2:C$13,E2),C:C,0))
in F2 and copy down.
If purely for display purposes you might filter ColumnsB & C an apply a "Top 10..." selection for 5 items.
We could 'cheat' and manage without INDEX in the example provided but, for wider applicability, having chosen the top five values in ColumnF these are then MATCHed to their row numbers in ColumnC and the corresponding row number fed in to the INDEX function to determine the B value.

The following is tested in Google Spreadsheets.
This would be a simple solution:
=MATCH(LARGE($C$2:$C$13,1),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,2),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,3),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,4),$C$2:$C$13)
=MATCH(LARGE($C$2:$C$13,5),$C$2:$C$13)
Another more precise way:
=LOOKUP(LARGE($C$2:$C$13,1),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,2),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,3),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,4),$C$2:$C$13,$B$2:$B$13)
=LOOKUP(LARGE($C$2:$C$13,5),$C$2:$C$13,$B$2:$B$13)

Related

How to use INDEX and MATCH to based to cells?

I have two sheets of data in excel. I want to combine cells to bring the second cell value. Here is an example:
when I enter combining columns name and list must get value form V1 and V2.like this:
I don't have the time to type your data, so this is a rare case of a non-tested formula and may need some tweaking.
For the V1 result: (top screenshot starts in Sheet1 column A, bottom screenshot in Sheet2, column A). This formula goes into cell B2 in Sheet 2:
=Index( Sheet1!$E$2:$E$100, MATCH(Sheet2!a2,INDEX(Sheet1!$A$1:$A$100&" | "&Sheet1!$D$1:$D$100,0),0))
Adjust the first index range from column E to F for the V2 result in C2.
Copy down.
Don't use that approach with whole columns. It will be slow. Use ranges with defined rows.
Of course, if the codes in Sheet1 column A are unique, you don't need to combine them with the value in column D and can look up only the first three characters, like this for V1 (use 6 for V2)
=vlookup(Left(Sheet2!A2,3),Sheet1!$A:$F,5,0)

Conditional Formatting (If/when)

Ok so I want a row to highlight red when the date in cell C1 is more than the cell in B1, but only if this is a difference of two months or less. I am sorry, I don't know how to embed a dummy spreadsheet. So for example, if B1 (clinic appointment due date) is Sep-17 and C1 (physical checks due date) is Oct-17, I want this row to highlight. If C1 is Dec-17, I don't want the row to highlight because this is more than two months from Sep-17.
Edited based on your new description, using Column A to represent Clinic Appointment Date and Column B to represent Physical Checks Due Date.
Use a rule based on DAYS().
Click on cell A1
Choose New rule from the Conditional Formatting menu.
Choose Use a formula to determine which cells to format
In Format values where this formula is true:, use the below formula:
=DAYS(B1, A1) < 60
Set up the formatting you want to use to highlight the cells. In the image below, I've set the ones that meet your requirements for highlighting to appear in red, and applied it to the first two rows in Column A (A1 and A2):
Here's the sheet with sample data in two rows, showing the conditional formatting working as requested:

excel vba: Specific data columns moving to the right

I am having trouble with writing a small code of VBA that does the following: In a huge dataset, search a particular column for entries that are obviously wrong (e.g. being above 50,when they should be from 1-10).I want this to find these entries,and copy alla the columns to the right of it and move them 3 columns further to the right.It is some sort of data cleaning.Thanks
Not sure why you would need VBA. Lets say that column A should be populated with numbers between 1 and 10. And columns B,C and D are populated with other data.
Select cell E1 and put in the formula =IF($A1>50,A1,"") in the formula box and push CTRL + Enter.
Use the drag handle to copy the formula into cells F1, G1, and H1.
With cells E1 through H1 selected, double click on the drag handle of cell H1.

Setting FormulaArray to Formula skips every other row and column

A very fast way to enter formulas is like this:
Range("E5:H10").Formula = "=A1"
The column and row references adjust, so that for example the formula this code enters in cell H10 is "=D6".
However, that doesn't work for array formulas:
Range("E5:H10").FormulaArray = "=A1"
That puts the array formula {=A1} in each of the cells; no adjustments for rows or columns.
Of course you can loop through all the cells and enter a unique array formula in each one, but that isn't fast.
So I tried this:
Range("E5:H10").Formula = "=A1"
Range("E5:H10").FormulaArray = Range("E5:H10").Formula
But the results were surprising -- the references skip every other row and every other column; for example:
-- The formula in F5 is {=C1} instead of the expected {=B1}, and
-- The formula in D6 is {=A3} instead of the expected {=A2}, and
-- The formula in H10 is {=G11} instead of the expected {=D6}.
WTF?? Why would it skip rows and columns like that?? BTW I'm in Excel 2007 SP3.
For now I'm doing this, which was the fastest way I found that worked:
Range("E5").FormulaArray = "=A1"
Range("E5:H10").FillDown
Range("E5:H10").FillRight
That works but is probably slower than the direct way would be. So -- why does setting the FormulaArray property to the Formula property skip referenced rows and columns as shown above?
The A1 formula is evaluated relative to the top left cell of the range you are populating. So A1 works fine in E5, but B1 is up 4 and left 3 from E5, so the formula entered into F5 refers to the cell up 4 and left 3, which is C1. This repeats for the other cells. The simple solutions is to use:
Range("E5:H10").FormulaArray = Range("E5:H10").FormulaR1C1
since that formula is the same for every cell.

sorting range based on other column values in Excel 2010

I have excel sheet contain data as below:
what we need is sorting range D2:E10 based on Column A values
we need result to be like this:
Is there any method allow us to do that?
(we recommend not to use macro if possible)
the closest solution with no macros is
select column a and d
use conditional fomat -> highlight cells Rules --> duplicated values
now all douplicted values cell color chaned
select range A2:B7 and custom sort using cell color, not colored cells at bottom
do the same with range D2:E10
hope this help you
I find some workaround solution
in cell F2 I used
=VLOOKUP(A2;$D$2:$E$20;1;FALSE)
and in cell G2
=VLOOKUP(A2;$D$2:$E$20;2;FALSE)
copy formulas to range F3: G10
this gives me some result but some data in range D2:E10 lost such as D4, D5 ...etc (not copied in column F and G )