Isolate Rows that Contain Certain Values in One Column (Excel) - excel

I need help with what I think is a simple Excel formula or function. I have two columns. As an easy example let's say the first column is numbers and the second column is colors:
| 1 | Red |
| 2 | Blue |
| 3 | Red |
| 4 | Red |
| 5 | Green|
| 6 | Brown|
Let's say I just wanted the rows with red in the second column and have everything else on the sheet deleted. How would I do that? To be clear, I want the values in column one to remain as well. This is how I would like it to look:
| 1 | Red |
| 3 | Red |
| 4 | Red |
It seems like it should be simple but I can't seem to find any way to do that. There are similar question on the forum but they are more complex than what I'm asking and require super long formulas. If that's what is required, I suppose that's what I'll do but just wanted to see if there was an easy way to do it as well. Thanks for the help!

You can use autofilter to filter the second column. Then select and copy the visible cells only, remove the filter, delete everything and paste what's in the clipboard.
Or do you need a dynamic solution? Then you could build a pivot table on a separate sheet. Put the desired color in the page filter and refresh the pivot table when the source data has changed.

Related

Function that enumerates based on data in other column

My question is inspired by this video: https://www.youtube.com/shorts/JZewxiKFplk
An Excel Table with data of names (and other data in adjacent columns irrelevant to this question). The Excel Table has data at different rows and there can be blanks arbitrarily in the table.
Like the SEQUENCE function featured in youtube video above, I am looking for a function that will generate in the column left of the Excel Table numbering for each row of data contained in the Excel Table. But unlike the youtube video above, the numbering should skip rows where there is no data, and continue its consecutive numbering for each row that contains data.
In the example below, left of "John" would be 1, left of "Mary" would be 2, and left of "Tom" would be 3. I'm not looking for a solution that would require I enter an Excel formula at every row of the Excel Table. I'm looking for a single formula like what's featured in the youtube video above. The formula should also be non-volatile.
Does a solution exist? As a last resort, if no Excel formula can do this, would a VBA solution work? The Excel Table will change size depending on the amount of data. Thank you very much for your help.
Example Excel Table of Data
| Name |
| -------- |
| |
| John |
| |
| Mary |
| |
| |
| |
| Tom |
| |
| |
Assuming your names are in B2:B20:
=LET(ζ,B2:B20,IF(ζ="","",SCAN(0,ζ,LAMBDA(α,β,α+(β<>"")))))

grouped and alternating conditional formatting

I have 3 sites, each of them have worked some tickets that I am reviewing. I would like to alternate between 2 shades of one color for each group: Site 1 would alternate between a lighter and a darker green, Site 2 would alternate between two shades of red, and Site 3 the same with Blue. However, I do not want to alternate every row, but rather every other ticket. The tickets may have a variable number of rows that are grouped with it. See screenshot where i have manually applied an example of the formatting im going for (these are not the final colors, these are used because the originals werent viewable after the image was uploaded).
Here is an image with the sample formatting:
Im fairly certain a helper column will be required here and while i'm fairly decent with excel and conditional formatting this one is a bit beyond me.
I will only use the Site column and Ticket column from your example to demonstrate my solution. Suppose the Site column is in Column A and Ticket column is in Column B, I will use Column C as the helper column in the following way presume the first row is for headers that do not need to be formatted:
In cell C2 enter number 1, this value is hard-coded/static;
In cell C3 enter the following formula and drag it down to the end of your table:
=MOD(IF(LEN($B3)=0,$C2,IF($B3=$B2,$C2,$C2+1)),2)
Then you should have a helper column showing either 1 or 0 based on the ticket number.
Highlight your table with cell A1 (i.e. the first cell of the range excluding header) being the active cell, set up the following conditional formatting rules one by one:
| Conditional Formatting Rules: | Format |
|-------------------------------|-------------|
| =(MAX($A$2:$A2)*10+$C2)=11 | Light Green |
| =(MAX($A$2:$A2)*10+$C2)=10 | Dark Green |
| =(MAX($A$2:$A2)*10+$C2)=21 | Light Red |
| =(MAX($A$2:$A2)*10+$C2)=20 | Dard Red |
| =(MAX($A$2:$A2)*10+$C2)=31 | Light Blue |
| =(MAX($A$2:$A2)*10+$C2)=30 | Dark Blue |
Then you should have the following:
Please note Column D Rule is for demonstration only which is not necessary in the actual table. It shows you how my formulas have differentiated each row based on Site and Ticket.
EDIT #2
Given that the Site ID are actually texts rather than numbers, here is an alternative approach, which is still using the helper column as illustrated in the original solution, but the conditional formatting rules will be changed to:
| Conditional Formatting Rules: | Format |
|---------------------------------------------------------------------------------------------|-------------|
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 1#1" | Light Green |
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 1#0" | Dark Green |
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 2#1" | Light Red |
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 2#0" | Dard Red |
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 3#1" | Light Blue |
| =(INDEX($A$2:$A2,AGGREGATE(14,7,ROW($A$1:$A1)/ISTEXT($A$2:$A2),1))&"#"&$C2)="Site Name 3#0" | Dark Blue |
Here is the screen-shot:
Let me know if you have any questions. Cheers :)

How to dynamically create or populate a worksheet with multiple rows, from a date range in a single row in another table

Given an existing excel TABLE with two date columns, representing the start date and end date. I would like to expand that table into a second excel TABLE in a different worksheet, so that there is one row for each of the dates between start and end. So for each row in the source table, add one row (in the target worksheet) for each date between start and end.
SOURCE TABLE:
|------------|------------|------------|------------|
|Person |Fruit |Start |End |
|------------|------------|------------|------------|
|Bob |Apple | 01/07/2019 | 04/07/2019 |
|Anna |Orange | 03/07/2019 | 05/07/2019 |
|------------|------------|------------|------------|
TARGET TABLE:
|------------|------------|------------|
|Date |Person |Fruit |
|------------|------------|------------|
| 01/04/2019 | Bob | Apple |
| 02/04/2019 | Bob | Apple |
| 03/04/2019 | Bob | Apple |
| 04/04/2019 | Bob | Apple |
| 03/04/2019 | Anna | Orange |
| 04/04/2019 | Anna | Orange |
| 05/04/2019 | Anna | Orange |
|------------|------------|------------|
A simple solution would create (or select) the target worksheet and generate all the rows required based on the data in the source.
An advanced solution would check the target worksheet to see if the rows already exist, and delete any that are not in the range. Note - I am adding this for the excel enthusiasts that really like to nail a solution. This is actually what I require, but I can build on the simple solution myself if required.
My motivation to do this is that Excel pivots and charting work best when there is a line of data in an excel TABLE for each item being analysed, much like how you would model the solution in a database.
For example, to chart the demand for oranges over time, a good pivot chart needs a single row for each date, rather than two dates expressing the start and end of the demand period (if that makes sense). Sure, you can do it with some indexing and cruel pivoting, but the user story for this spreadsheet makes that technique impossible. It must be generated automatically.
EDIT: Just adding that I appreciate that I can achieve this by adding a column for each date into the source table, and using Transform Data to generate the dataset. However, the design of the real world source table (rather than this example) has limitations set by the user that prevent me from doing so. I do also have a working method where I copy the source table to a temporary sheet, and then run a transform on that, but the user would like me to try to avoid doing that (ho-hum!)

Excel: retrieve data based on a column

I have an excel document with a checklist like this one:
| number | yes/no | notes |
| 1 | yes | blablabla |
| 2 | yes | twinkle twinkle |
| 3 | no | little star |
I'd like to "echo" the fields which are set as "no" (in the second column) in another sheet, echoing the columns "number" and "notes". The result of my example would be:
| number | notes |
| 3 | little star |
How could I do it? Thanks!
Assuming your Main Table is in Sheet2, range A2:A4 (row 1 being headers). Use this formula, as an array (enter with CTRL+SHIFT+ENTER) in your sheet 2:
=INDEX(Sheet2!A$2:A$4,SMALL(IF(Sheet2!$B$2:$B$4="No",ROW(Sheet2!A$2:A$4)-ROW(Sheet2!A$2)+1),ROWS(Sheet2!A$2:A2)))
This will return all the Numbers. To get the Notes, change the very first index range to Sheet2!C$2:C$4. Obviously adjust your range down as necessary (I doubt you only have 4 of these).
Finally, just wrap an IfError() around that, so it looks nice when you use it. As you add data to your table, your table of only "no" values will update.
=IfError(INDEX(Sheet2!A$2:A$4,SMALL(IF(Sheet2!$B$2:$B$4="No",ROW(Sheet2!A$2:A$4)-ROW(Sheet2!A$2)+1),ROWS(Sheet2!A$2:A2))),"").
edit:
Screenshots:
(Using the IfError([above formula],"") wrapper hides the #NUM results when there's no match.)

EXCEL find the last relative maximum in a array (formula, not VBA)

I have a range containing values such as:
169.7978
168.633
168.5479
168.7819
167.7407
165.4146
165.1232
I don't need the maximum value of the range, i.e., the first cell in this example), but the last relative maximum, which in this case is the fourth cell. Is there a way to get this value without having to write a VBA macro? The formula must be general enough to work with a multiple number of maxima.
It may be a bit limited, but you may start somewhere as below.
Stated array in the OP is:
+----------+---+
| y | x |
+----------+---+
| 169.7978 | 1 |
| 168.633 | 2 |
| 168.5479 | 3 |
| 168.7819 | 4 |
| 167.7407 | 5 |
| 165.4146 | 6 |
| 165.1232 | 7 |
+----------+---+
Given this, you can find direct adjacency relative min/max with the following helper columns
Assign a Global_Rank helper column and look for y distro identical trend on both adjacent f(x) with the following formulas ( assuming your data is sorted by the x index )( formulas from Row 2 and filled down ).
RelativeMax:
=IF(AND(D2<=D1,D2<=D3),"RelativeMax","")
RelativeMin:
=IF(AND(D2>=D1,D2>=D3),"RelativeMin","")
Modify as needed. Hope this helps.
Edit:
Although...
If you're going to assume the data is ordered properly, you could also just use =IF(AND(B2>=B1,B2>=B3),"RelativeMin",IF(AND(B2<=B1,B2<=B3),"RelativeMax","")) and skip all the malarkey. This should work with multiple maxima/minima. Please report back with results from your dataset!

Resources