I have numbers lets say (in one row or in one column)- 1011,3021,5683,9274,1002
Now I have array named "myArray" like below:
1011 68542 136814
3021 112054 79216
5683 136814 1002
68542 79216 9274
144797 1002 1011
98150 9274 98150
112054 112054
Now I want to highlight those numbers from "myArray" which are not listed in 1011,3021,5683,9274,1002 (row or column value)
Can anyone give me the formula or macro?
I tried with conditional formatting, index match, Hlookup, Vlookup....
You can use conditional formatting
Create a list A1:A4 -> example 1, 2, 3, 4
Create a list B1:B2 -> example 2, 4
Create a conditional formatting on the fist list (A1:A4)
Select at Format rules Custom formula is
Put in Value or formula box =MATCH(A1:A4,B$1:B$2,0)
Now the A2 and A4 (value 2 and 4) should be highlight
Return value
A number representing a position in lookup_array.
Syntax
=MATCH (lookup_value, lookup_array, [match_type])
Arguments
lookup_value - The value to match in lookup_array
lookup_array - A range of cells or an array reference
match_type - [optional] How to match, specified as -1, 0, or 1. Default is 1
Related
A 1
B 2
C 3
I want add number by choosing alphabet, and like if choose A & B in formula then cell must show sum value 3 and even if I shuffle the alphabet upside downside it still show the 3 by analyzing alphabet.
I first checked which of the key values are present in the user-provided input string. I made a new column where I assigned an extra value of 0 to those that are not present in the input string, and a value of 1 to those that are. I then multiplied that binary column with the corresponding value, and then summed them all up.
I started with FIND(), which will tell you where the value of the key letter starts in the input string. E.g., =FIND("A", "BAC") will return 2, because "A" starts in the second position of "BAC".
This will return an error if the string can't be found, so I surrounded the output of the FIND() with IFERROR(). IFERROR takes in an expression and lets you specify what you want the output to be if the expression returns an error. I set the error output value to be '0'.
I then surrounded all of that with an IF() statement. If the value is 0, leave it as 0. If it's greater than 0, set it to be 1.
This IF(IFERROR(FIND())) expression will produce a 0 or a 1 for each key letter, which you can then multiply with that key's value to obtain how much that key contributes to the final sum. And then it can all be added up neatly.
Screenshot of final spreadsheet
The important cell formulas are:
C1: (whatever your input string is)
C2: =SUM(C5:C7)
A5: A
A6: B
A7: C
B5: 1
B6: 2
B7: 3
C5: =IF(IFERROR(FIND(A5,$C$1),0)>0,1,0)*B5
C6: =IF(IFERROR(FIND(A6,$C$1),0)>0,1,0)*B6
C7: =IF(IFERROR(FIND(A7,$C$1),0)>0,1,0)*B7
I have a table with specific products and dates and I want to get the cost values that correspond to that date . The source table has a range of dates and not an actual match (that is my problem).
Here is the task: we are trying to fill column "Cost" based on Sheet 2
SHEET 1:
Product
Date
Cost
price
First
29/12/2021
result 1 (formula type X)
100
Second
05/01/2021
result 2 (formula type X)
200
The other Sheet has the date ranges with the desired results (selling prices), like this:
SHEET 2:
Product
Start Date
End Date
Cost
First
28/12/2020
03/01/2021
result 1
Second
04/01/2021
11/01/2021
result 2
PS. I have different costs for different products in the same date. So, we needed to also add a parameter that will match the Product from one sheet with the product of the other.
If the given Ranges both start at A1 and end at D3 then the following works in Sheet1!C2:
=INDEX(Sheet2!D:D,MATCH(1,(B2>Sheet2!B:B)*(B2<Sheet2!C:C)*(A2=Sheet2!A:A),0))
This is an array formula to be entered with ctrl + shift + enter
It Indexes sheet2 column D and searches for the first match where all mentioned condition are true (=1). Each condition produces 1 or 0 for each cell in the range and multiplies it by the result of the cell from the next range in the same row. If either of the conditions is false it multiplies by 0 resulting in 0.
If all conditions are true it will result in 1 (111).
The overall produces an array of {0,0,1,0,...} and the match function returns the N'th occurance of the first 1, which is equal to the row number of the conditions being true.
Since you mentioned tables I'm going to assume you mean a real Excel Table and not just cells formatted into a table like appearance.
Sheet 1 Table is named: tbl_ProductPrice
Sheet 2 Table is named: tbl_ProductCost
"Cost" column formula in sheet 1:
=SUMIFS(tbl_ProductCost[Cost],[Date],">="&tbl_ProductCost[Start Date],[Date],"<="&tbl_ProductCost[End Date])
Explanation
First SUMIFS parameter, "Cost" column, is what will be summed up if all criteria are true.
First IF:
Second parameter is the date criteria to check.
Third parameter is what to check against, is greater than or equal to start date.
Second IF:
Fourth parameter is the date again for the second if statement
Fifth parameter is checking if less than or equal to the end date.
Results:
EDIT
Based on your comment regarding multiple product entries for different date ranges I would go with the Index Match approach instead.
=INDEX(tbl_ProductCost[Cost],MATCH(1,([#Product]=tbl_ProductCost[Product])*([#Date]>=tbl_ProductCost[Start Date])*([#Date]<=tbl_ProductCost[End Date]),0))
Enter formula with Ctrl+Shift+Entersince it's an array formula.
I added in a product match as well since you indicated multiple date ranges for each product type.
Results
I am currently using the following subtotal SUBTOTAL(9,b:b) to cat a total on my filtered data.
Column A contains a year of either 16,17,18 or 19.
I would like to only count the subtotal if column A contains 16 so
=if(a:a = 16, SUBTOTAL(9,b:b) or something simular
We can "fake" the SUBTOTAL() function. Say we have data like:
and we want to filter the data and only add values in column B that correspond to 16 in column A. In C2 enter:
=SUBTOTAL(3,$B2:$B2)
and copy downward. Then filter column B for positive only:
The cool thing about column C is that it is 1 if the row is visible and 0 if the row is hidden. Therefore:
=SUMPRODUCT((B2:B20)*(C2:C20))
will yield the same result as =subtotal(9,b:b) and:
=SUMPRODUCT((A2:A20=16)*(B2:B20)*(C2:C20))
will apply the column A restriction.
I have a worksheet that has information like this:
a
a
b
c
c
c
How do I format it so that all of the rows that have a value of a in the first column are one color, then all the rows that have a value of b in the first column are a different color, etc. ?
Edit not from OP to add clarification from comment:
Everything is already sorted alphabetically, and will stay that way, and I want multiple colors.
Create a helper column with a formula like this;
=MOD(IF(A3=A2,0,1)+B2,2)
In this example column A is the column of sorted values to be grouped by, and column B is the helper column. The formula is entered on row 3. Set the first row of the helper column to the value 0 and the others to the formula. This will result in alternating values in the helper column for each group, ie;
a 0
a 0
b 1
c 0
c 0
c 0
d 1
d 1
e 0
You can then set conditional formatting based on the column value. If the value is 1 then highlight the row; if it is 0 do not highlight it. Or use alternating colors or whatever. You can reference any of the articles on the web that describe how to conditional format the entire row based on the value in the column.
IF(A3=A2,0,1) compares the current row (3) and prior row (2) returning a 1 or 0.
MOD( [...] +B2,2) accomplishes the alternation between 0 and 1 when the grouping column value changes.
I think you need a helper column, say B seeded with 1 in row1, and =IF(A1=A2,B1,B1+1) in B2 and copied down to suit. Then formulae of the kind below should suit for conditional formatting:
I have 2 columns looking like this:
Column 1 Column 2
1 x
x 2
2 2
x x
1 2
I want to do two things;
For each row match (row n column 1 = row n column 2) it should mark cell n in column 1 green if there is a match and red if it is not.
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points.
Is this even possible with excel and if so, how is it done?
For the first part of your question:
It should mark cell n in column 1 green if there is a match and red if it is not
You can do this using Conditional Formatting.
Ex:
Assume column A and column B, with the values starting in row 2.
The following conditional formatting would highlight column A values in green if they match the corresponding value in column B in the same row, otherwise red.
Highlight the values in column A, then apply this conditional formatting.
For the second part of your question
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points
The following array formula will tally all the matches and show you how many there are:
=SUM(IF(A2:A6=B2:B6,1,0))
Assuming again that we are in columns A & B with your sample data.
Remember to commit this formula using Ctrl+Shift+Enter.
Per comment from andy holaday, here is another formula that will work:
=SUMPRODUCT(N(A2:A6=B2:B6))
or
=SUMPRODUCT(--(A2:A6=B2:B6))
These are not CSE formulas so you would not need Ctrl+Shift+Enter to commit them.