How to determine current row? - excel

I am using Conditional Formatting to try and change the colour of a cell in column A if the text in Column B is certain values. Currently my three formula's are this:
=$B$2="Low"
=$B$2="Good"
=$B$2="High"
I need a way to quickly push this to all 50 columns therefore I thought if I could change the formula to the following it would work I just don't know how:
=$B$ThisCellsRow()="Low"
=$B$ThisCellsRow()="Good"
=$B$ThisCellsRow()="High"

You're using absolute cell references (the $ in the address), which prevents Excel from adjusting the address as you add/remove rows and move the formula around. If you use $B2 instead, as you drag down the formula, Excel can adjust it to be $B3, $B4, $B5 and so on. With this format, the B column remains constant, and the row portion is flexible.

Related

Conditional formatting based on the content of a formula

Long story short: My boss has an Excel spreadsheet for calculating product prices. She has three columns to calculate different margins (so would contain a formula like =cost*.5 etc.), then adds to those values to determine final retail (so would be =column+500). She has her margin columns highlighted different colors and wanted to automatically highlight the final retail cell based on which margin column it references.
I'm sure there's a way of setting up the document from the start that makes this more intuitive, but short of restructuring her entire system, are there any formulas I could use in combination to return a format based on the content of the formula?
I immediately assumed to use "if cell contains specific text" and use the referenced column letter as the text, but excel reads the output for the formatting and not the formula, so I am stumped.
I was thinking somehow to use "isformula", but all the values are formulas just with different input.
Suppose you made table of all the unique formulas that are used:
formula_test, rule,
=cost*0.5,1
=column+500,2
Then you could create conditional formatting rules by formula with one for each unique formula case.
=VLOOKUP(FORMULATEXT(A1),$A$2:$B$3,2,FALSE)=1
=VLOOKUP(FORMULATEXT(A1),$A$2:$B$3,2,FALSE)=2
Where A1 is the first cell in the range where you want the conditional formatting to be applied.
The missing link was "SEARCH":
=SEARCH("=Sum(J",FORMULATEXT(N2))
(J = the referenced margin column, N2 = first cell to apply the final retail formula)

How to highlight four random selections from a column?

I'm trying to randomly highlight (change the cell colour) of four cells in the first Excel column. It is important the selections highlighted are only cells containing data as the size of the data set will vary.
The highlighted selections needs to be un-highlighted when the macro is run again to generate four new selections.
I have tried to brute force this with functions (RAND-RANK-XLOOKUP), but the outcome is messy and doesn't react to different sizes of data.
Highlighting the cells in a color is the goal, conditional formatting could be suitable.
Four random cells from the first column of the Excel sheet is the target (cells only containing data).
Using Conditional Formatting
Let's say you have data in column A. For example 16 rows like this:
You could use the COUNT() function to calculate the number of cells with content in column A in cell D1 :
=COUNT(A:A)
And then you could calculate the position of the cells you want to highlight with
=RANDBETWEEN(1,$D$1)
Then you can create a helper column to check if a cell should be highlighted.
Formula in G2 : =IFERROR(MATCH(CELL("row",A2)-1,$D$2:$D$5,0)>0,FALSE)
The idea behind this function is simply to check if the row of the data point corresponds with one of the random positions we have.
Finally, you would use a formula to define your conditional formatting by applying it to Column A and using =$G2 as the formula.
Note that:
The highlighing will reset everytime you change a cell provided that you have "Automatic calculations" turned ON.
There is a possibility that 2 or more of the random positions are the same, so you'll need to recalculate if that's an issue.

Excel, how to prevent data from incrementing but also not copy formatting

I am trying to drag the bottom right corner downwards to copy some data and it always increments my numbers that I want to copy. If I select copy cells in the auto fill options then it copies the numbers properly but also copies the formatting, but if I select fill without formatting it increments the numbers. I want both. My first cell has a strong border above it that I don't want every cell to have. However my data is in semi small increments of the same problem so copying the first cell once then dragging would be way to inefficient. Thanks for the help.
Original data example
Using copy cells, right numbers wrong formatting
Use the following formula in the any one of the columns you are not using and drag it down to the end of data. Then copy the result to your column E as values. If your helper column is N then:
=IF(E3<>"",E3,N2)
What I usually do in these situations is separate the values from the formatting.
make a copy of the column you want to edit (either adjacent to it,
or outside the table you're editing).
On the new column - use copy cells in the autofill menu, or
otherwise complete the values according to your needs.
paste the new column back on the original column As values.
Delete the new column

Excel - Time Intersection

I want Excel to check whether two time intervals intersects or not.
For example, I3-J3 and I5-J5 intersects.
How can I make Excel to show this intersection in another cell?
The following formula will reveal any interference for the last row. Just copy this formula into cell K3 and copy it down:
=IF(OR(AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2))),AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2)))),"interference","OK")
Note that this is an array formula which will have to be entered using Ctrl+ Shift + Enter. For more information on array formulas you might want to read the following article: https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7D94A64E-3FF3-4686-9372-ECFD5CAA57C7
If you want to show interference for both rows then you'd have to expand upon I$2:I2 and J$2:J2 to include the entire list. So, this might be (for example) I$2:I$500 and J$2:J$500 respectively. Yet, you cannot include the row itself. Otherwise, you'd always get interference because the formula would check against itself. So, you'd have to generate individual formulas for each row and you cannot enter a generic formula and copy it down.
I am not sure how to show (with formulas only) the interfering entry. This is mostly due to the fact that there might be more than one interfering entry which would then have to be listed and separated by ,. I don't think that can be done with formulas only.
Note: the above solution is based on the basic principle that all dates and times in Excel are (essentially) just numbers formatted as dates or time. For more information you might want to read the following: Change date format using substitute or replace
So, the above formula is just checking if the date in column I is between any prior date in column I and column J. If the date in column I is > and prior date in column I and also < compared to the date in column J then this is an interference. The same has to be checked for the date in column K and then both have to be combined with an OR. That's the entire formula above.
Update:
Based on the comment provided by #Gordon the formula can be improved with the COUNTIFS function. Just enter the following formula into cell C2 and copy it down:
=SUM(COUNTIFS(A:A,"<"&A2,B:B,">"&A2),COUNTIFS(A:A,"<"&B2,B:B,">"&B2))
Any number greater than 0 means that there is at least one interference. With this formula it is now counting / showing multiple interferences as you can see in the following screenshot:
Note, that the improved formula does not require anymore for you to know the range of the table. Instead you can search the entire column A:A and B:B for interferences.

Unique value in excel

I have an array of numbers in Excel spanning from Cells B1 to F49. Out of all those numbers I want to find out the unique values, in other words, no duplicates. I tried using Remove duplicates but it looks at the rows and not the individual cells. What would be my best option for doing this? any help would be greatly appreciated.
You could try this array formula that returns unique text or numbers from a rectangular range.
Select a range to output the results to eg: H1:H245
Copy and paste the formula below into the formula bar.
Press Ctrl+Shift+Enter to enter into the range.
=IFERROR(CELL("Contents",INDIRECT(T(IF(1,TEXT(MODE.MULT(IF(FREQUENCY(COUNTIF(B1:F49,"<="&B1:F49)+ISTEXT(B1:F49)*COUNT(B1:F49),COUNTIF(B1:F49,"<="&B1:F49)+ISTEXT(B1:F49)*COUNT(B1:F49))>={1,1},MODE.MULT(10^5*ROW(B1:F49)+COLUMN(B1:F49),10^5*ROW(B1:F49)+COLUMN(B1:F49)))),"r0c00000"))),0)),"")
I'd probably put this formula in column C: (or another empty column you have):
(so starting in cell C1: )
=COUNTIF(B:B,B1)=1
(and copy/paste the formula down)
It will return TRUE if it is unique. So you can then filter things out via Filter, or with other formulas down the road.
It may be easiest to just combine your information into one long column and run a remove duplicates. If this is not an option you may want to look at writing a macro to crawl through the records.
You could have a macro go through each column for the rows specified and determine if the CountIf function =COUNTIF(B2:F49,B2) returns a value >1
if it does there are at least 2 instances of this number.
I'm not sure how you want to identify your unique cells but you could potentially set a text color or return the values of the cell to another location.
Simplest for identification of values unique within the entire array may be to highlight the entire range with ‘standard’ formatting of choice for uniques, then select the entire range, Conditional Formatting, Highlight Cell Rules, Duplicate Values…, and choose a custom format of no fill and font of whatever you started with.

Resources