How do I structure my if text then colour statement - excel-formula

I am trying to match products with prices.
There are 5 different products named as; "green", "red", "blue", "black" and "brown" and their corresponding prices are £10, £10, £10, £10 and £5 respectively.
Suppose the current input product is "green" in cell B15 then the price £10 will automatically be assigned to cell F15.
I want to achieve this for any new data I put into the spreadsheet

Build a table of your products. Place the product names on the left and the prices on the right. Use a VLOOKUP function in F15 to find the price from the table based on the product selection in B15. For the example below the VLOOKUP formula is as follows:
=IF(B15="","",VLOOKUP(B15,$D$9:$E$13,2))
The VLOOKUP function is wrapped inside the if function so that nothing is displayed as long as cell B15 is blank. You could also wrap it in an IFERROR function to display NOT FOUND, blank or 0 for those occasions where something is entered in B15 that is not in the list. You can also use data validation on cell B15 and set it to a list option then set the list to be your first column. This will provide a pick list, prevent typos and prevent entries that are not a part of you table.
Data validation list

Related

How to remove a value (from the adjacent cell) in the drop-down list?

I have two columns Product 1 and Product 2, both of which lets user select from a dropdown list. But I don't want to show the same value in Product 2 if the user selected it for Product 1 in the same row.
The formula I am using for the drop down list is:
='Details'!$C$2:$C$500
If helper columns are allowed drop this formula into D2 and drag down:
=IF(C2=PRODUCT1,"",C2)
I don't know what cell the first dropdown is, just plug that cell ref in where I said PRODUCT1
, make sure to use $ to lock the cell ref. (ex. A1 become $A$1)
Then select your second drop down and set its data validation to ='Details'!$D$2:$D$500
It will leave a blank where the value used to be.

Excel validation dropdown - populate with relevant values based on category

So I have two categories - lets call them 'Cars' and 'Vans'. The first sheet in the workbook has a list of vehicles with the category name in the cell to the left:
CATEGORY VEHICLE ID
Car 12987
Van 28374
Van 34872
Car 38747
Car 48726
I want to use that list elsewhere in the workbook to populate validation dropdowns. Is there a way to pass a category name (i.e. Vans or Cars), search the left column for cells that match that value, then where there are matches populate the dropdown with values from the adjacent ID column?
Data Validation will only accept ranges, not arrays, and the ranges have to be contiguous, so you'll have to use a helper range or sort by CATEGORY. To replicate the results shown in the images, follow the steps below.
Enter this as an array formula in C2 (ctrl+shift+enter) and fill down:
=IF(COUNTIF($C$1:C1,C1)<COUNTIF($A$2:$A$6,C1),C1,INDEX($A$2:$A$6,MATCH(0,COUNTIF($C$1:C1,$A$2:$A$6),0)))
Enter this in D2 (again as an array formula) and fill down: =INDIRECT("B"&SMALL(IF($A$2:$A$6=C2,ROW($A$2:$A$6)),COUNTIF($C$1:C2,C2)))
Enter this as the Data Validation list formula in G2, then fill G2 down to G3:
=INDIRECT("D"&MATCH(F2,$C$2:$C$6,0)+ROW($A$1)&":D"&MATCH(F2,$C$2:$C$6,0)+COUNTIF($A$2:$A$6,F2)+ROW($A$1)-1)

Excel top n list by criteria (including between dates)

I am trying to figure out how to make a top n list of the most common textvalue in an excel spreadsheet based og 2 criterias (between dates and text).
Assuming i have a list as shown in image below. In columnE i want to be able to list the top n colors from columnB based on the criteria that it's a Bmw (columnA) sold within 2017 (ColumnC)
Hope someone can help !
If you are happy to use Pivot Tables, here's a way to achieve this:
Use Sold Date as filter, Car in Columns and Colour as Rows. Then have Count of Colour as Values.
On the row Labels filter, use Value filter and at the bottom you have Top 10... which you can set to top 3.
Following might be helpful.
In Cell G2 enter following formula
=IFERROR(INDEX($B$2:$B$14,MODE(IF(A$2:A$14=E2,IF(YEAR(C$2:C$14)=F2,MATCH(B$2:B$14,B$2:B$14,{0,0}))))),"")
In Cell H2 enter
=IFERROR(INDEX(B$2:B$14,MODE(IF((A$2:A$14=E2)*(YEAR(C$2:C$14)=F2)*
(B$2:B$14<>INDEX(B$2:B$14,MODE(IF(A$2:A$14=E2,IF(YEAR(C$2:C$14)=F2,MATCH(B$2:B$14,B$2:B$14,{0,0})))))),MATCH(B$2:B$14,B$2:B$14,{0,0})))),"")
In Cell I2 enter the below formula
=IFERROR(INDEX(B$2:B$14,MODE(IF(((A$2:A$14=E2)*(YEAR(C$2:C$14)=F2)*
(B$2:B$14<>INDEX(B$2:B$14,MODE(IF(A$2:A$14=E2,IF(YEAR(C$2:C$14)=F2,MATCH(B$2:B$14,B$2:B$14,{0,0}))))))*
(B$2:B$14<>INDEX(B$2:B$14,MODE(IF((A$2:A$14=E2)*(YEAR(C$2:C$14)=F2)*
(B$2:B$14<>INDEX(B$2:B$14,MODE(IF(A$2:A$14=E2,IF(YEAR(C$2:C$14)=F2,MATCH(B$2:B$14,B$2:B$14,{0,0})))))),MATCH(B$2:B$14,B$2:B$14,{0,0})))))),MATCH(B$2:B$14,B$2:B$14,{0,0})))),"")
All the above formulas are array formula so commit by pressing Ctrl+Shift+Enter. Drag/Copy down as required.
Note : In case there's a tie for any position, color appearing first in the range will be the result.
See image for reference.

It is possible to make 2 dropdownlist with different based on 1 value in a cell?

After reading many tutorial, I managed to make a well effective dynamic dropdownlist
My question is , let's say I want to add a third depend cell, and the problem the name of MyCell is already used once
I'm using this line of code to bind the first dropdownlist (INDIRECT(SUBSTITUTE($U22," ","")&"Col")),1)
Is it possible to add to this line of code something like
(INDIRECT(SUBSTITUTE($U22+"Other"," ","")&"Col")),1)`
as to bind the second dropdownlist so I can name a cell :MyCellOther witch contains the other value I want to add
I'll elaborate on what I meant in my comment above:
The name of a Named Range can be anything you want that isn't already used as a term by Excel. When naming your ranges, you should be careful to use logical terms which intuitively show what they mean. If you are using a series of similar names in an ordered list, consider simply numbering them 1 to 9, or instead consider using a 2D block of data as a single range. I will show you how to do both.
Explanatory Example of multi-tiered dropdown lists - 2 methods
Sheet1 is going to hold the end-user's dropdown selection. Sheet2 is going to hold your raw list database.
On Sheet1, assume A1 is a cell that allows a user to enter in what type of pie they want. There are 2 types: Fruit or Meat. Further, there are two sub-categories within each type: Fruit (Summer) / Fruit (Winter), or Meat (Red Meat) / Meat (Poultry).
If a user enters the type of pie they want in A1 (could be a dropdown itself), we want A2 to show a dropdown list that allows them to further choose which sub-category they want. Then, we want A3 to show a dropdown of each specific pie based on that sub-category within the main type.
Creating the Dropdown list in A1
On Sheet2, A1 enter "Fruit", and then on A2 enter "Meat". Select A1:A2 on sheet2, and name that range "MAIN_TYPES". On Sheet1, A1, make a dropdown list that is limited to "=MAIN_TYPES". This will create the first dropdown list.
Creating the sub-category dropdown list in A2 using a 2D block of data
First, organize your data on sheet2. On Sheet2 B1, type Summer, on C1 type Winter. On Sheet2 B2 type Red Meat, on C2 type Poultry. Select B1:C2, and name that range "SUB_CATEGORIES".
So, the user has already selected either Fruit or Meat. We want this dropdown list to only show the sub-category of that particular type. We can do this by referencing the fact that Sheet2 row 1 contains the fruit pies, and row 2 contains the meat pies.
On Sheet1 A2, make the cell a dropdown list which refers to the list SUB_CATEGORIES. But, we want to limit it so that it doesn't show the categories for the 'other' pie type. If we wanted to hardcode this to only show the Fruit sub-categories, we could use:
=INDEX(SUB_CATEGORIES,1,0)
This says - take row 1 of SUB_CATEGORIES (the fruit row), and for the column, take ALL columns (we show this by putting the '0' above; it assumes we want all the available columns, which is quite handy).
To make this dynamic and based on the selection of A1, we can replace the '1' above with the MATCH formula, which looks at where a specific search string was found in a row/column of data. Like so:
=INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0)
This searches for the type of pie picked in A1, out of the MAIN_TYPES range, and then returns that row number to the INDEX Function. So now, this INDEX function returns a single row (and both columns) of the sub-categories, based on the row which aligns with the MAIN_Type chosen.
Creating the dropdown list in A3, using numbered Named Ranges
On sheet2, add in the final block of data - the specific list of each type of pie. On D1 type Peach, on D2 type Cherry, on D3 type Rhubarb; Name this list Fruit1 [this will be the summer fruits]. On E1 type Apple, on E2 type Pumpkin; Name this list Fruit2 [this will be the winter fruits]. On F1 type Beef, on F2 type Lamb; Name this list Meat1 [this will be the Red meats]. On G1 type Chicken; Name this cell Meat2 [this will be the Poultry].
Now, on Sheet1, cell A3, the user will need to pick which pie out of the type and sub-category already chosen. If we wanted to hardcode this to be winter fruits, the formula for the dropdown list would simply be:
=Fruit2
But, we want to only show the winter fruit options if that was chosen above. Consider: if we wanted to allow the user to just type "Meat1" into A4, we could put the following formula in A3, and it would show that list:
=INDIRECT(A4)
Instead of having the user type in the name of the Sub Category, we will take the information they have already provided, and combine it to create that name. Specifically, we will combine (1) the main of pie the user has already chosen, with (2) the Column number of the Sub_Category they have chosen. The Main type they chose is simply the text in A1. The column number of the Sub Category is found using the Index & Match function, similar to above:
=MATCH(A2, INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0),0)
Remember above, the formula '=INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0)' gave us the row that aligned with either Fruit or Meat. Here we take that row, and use MATCH to find the column # that aligns with A2. We can combine all of this together with the text in A1, and it will give us the name of the Sub Category for the final dropdown list in A3:
=INDIRECT(A1 & MATCH(A2, INDEX(SUB_CATEGORIES,MATCH(A1,MAIN_TYPES,0),0))
And that's all there is to it.
The above can be extrapolated for your data, but it shows how to (1) do a dropdown list that refers to a named list of MAIN_TYPES; (2) Do a dropdown list that looks for a specific row in a 2D range of SUB_CATEGORIES; (3) create a 'cascading' dropdown list using the Indirect function; and (4) use numbers in the name of a range to refer to multiple similar lists.

How to look up value in a column, and assign specific entries

I have a sheet in Excel where the columns contain different names of people that are in different teams in my department (i.e. Names in Column 1 are in Team 1).
For another sheet, I need to have a formula that achieves the following:If I write a name in Cell B2 that can be found in the first column of that other sheet (Team 1), Excel should populate cell B6 with "Team 1".
If instead, the name I wrote is found in the second column, then the text should read "Team 2".
I've tried a couple of different formulas w/o success, and stringing a lot of IF and OR functions together is way too cumbersome. Anybody has a better solution?
If you need this formula for more then only two column then id use the formula
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6)))
Say you have a set-up like:
And in B1 of Sheet2 you enter Name3, you want it to return TEAM1 as shown below:
The only catch to this formula is that you will need to tell it how many columns are before your data so if you have a table more like:
Then you need to tell the formula that there are 2 rows before your data starts, your new formula will be
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6))-2)
Notice the -2 before the last parenthesis this is to indicate that there are 2 columns BEFORE you data.
and the new result for looking up say NAME20 would become as follows:
*EXPLANATION: *
The formula works as follows , I will do it all on one page for easier viewing and instead of Sheet2!B2 and B6 I will use G2, and G6 on the same sheet as the data.
First we look at all values in the Range A1:E6 and find the one with the matching name so we use
=A1:E6=G2
Now when you enter this into the cell you will recieve a #VALUE,but if you goto the Formula Bar and press F9 it will shwo you the full value of the formula
{FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE}
In this we know that one cell contains the Name we searched for, this is represented by the TRUE
Now when using a formula like SUMPRODUCT, FALSE = 0 and TRUE = 1
So to get the column we mutiply every result by the column they are in.
=SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6))
So any cells that don't =G2 are FAlSE or 0, and when you multiply the column of that cell by 0 (because false = 0) it will simply result in 0. But for the one cell that IS TRUE or 1 When you multiply the column of that cell by 1 (because TRUE = 1) The product will be the cells column number
So as shown in the picture when looking for NAME13 the result of the sumproduct is 3 (its column)
Then to return the TEAM for that name, we use the INDEX function will return the value in a cell at the given cordinates.
In this case we want the value from A1:E1 that is in the same column as the Name we matched. When looked at as an Array A1:E1 looks like
{"TEAM1","TEAM2","TEAM3","TEAM4","TEAM5"}
And we want to return the value in that array at the same position as the column number of our cell, Minus any nonincluded column before the data, thus the reason for the -2 in the secon example I gave you.
So:
=INDEX(A1:E1,SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6)))
In this example excel interprets this formula as
Return the 3rd value (the 3 comes from the sumproduct as explained earlier) in the list of value from A1:E1. And that value would be TEAM3.
use a MATCH() or VLOOKUP() function inside an IF(). SOmthing like:
IF(NOT(ISERROR(MATCH(...)));"Team1";"")
Did you know you can browse functions by catergoty (such as Search), just clikc the fx left of your formula bar and use the drop down box. Each formula comes with a description with usually rather clear information...

Resources