IF function with coordinates (Excel) - excel

I am looking for a formula that would make my life much easier. I have a table with simple coordinates in the columns and coordinate combinations in the rows. I want Excel to indicate when a coordinate is included in the coordinate pairs. The output should be 0 and 1 (see picture). I was thinking of a If function, but I didn't know how to implement it.
My example has a total of 13 different coordinates, so you can imagine how much work this would be by hand.

Formula in Cell B2 is:
=COUNTIF(B$1;"*"&$A2&"*")
Notice I'm using mixed references. Just drag to right and to bottom and it will work.
COUNTIF
function
Switch between relative, absolute, and mixed
references

Related

How to correctly formulate a sum function with range in excel

I'd like to write this function in excel:
It's a function that calculated how much experience is needed for a particular level.
level 2 is 83xp, level 99 is over 13,000,000 for example.
I have all the levels arranged in this way:
I just can't figure out the excel formula to put into cell 4B to calculate the function in the image. I'm thinking it should be something like
=floor(sum[1 to cellToLeft.value - 1](floor(x + 300*2^(x/7))/4))
but that's not quite right
This seems to work for me:
{=FLOOR(SUM(FLOOR(R4C[-1]:RC[-1]+300*2^(R4C[-1]:RC[-1]/7),1))/4,1)}
Make sure you enter as an array formula.
If you don't use R1C1 mode then you need something like this:
{=FLOOR(SUM(FLOOR(A$4:A12+300*2^(A$4:A12/7),1))/4,1)}
This will be an array formula in excel answer. Place the level you want (the value for L) in N4, or change the reference to suit your needs. Enter the following formula in the cell you want the answer to be in remembering to press CONTROL+SHIFT+ENTER when finishing the formula instead of just ENTER. You will know you have done it right when {} appear around your formula in Excel.
=FLOOR(SUM(FLOOR(ROW($A$1:INDEX(A:A,$N$4-1))+300*2^(ROW($A$1:INDEX(A:A,$N$4-1))/7),1)/4),1)
Level 1 will cause an error since L-1=0. Since I am assuming it takes 0 for level 1, I threw in a error trap. anytime the formula returns an error it give a value of 0 instead. With the following formula you can change the $N4 reference to where ever you have your level 1 value. remember to use C+S+E when you enter the formula and copy downward as far as your levels go.
=IFERROR(FLOOR(SUM(FLOOR(ROW($A$1:INDEX(A:A,$N4-1))+300*2^(ROW($A$1:INDEX(A:A,$N4-1))/7),1)/4),1),0)

How to set the background of three cells based off of the value in one other cell, relatively?

I'm trying to make a formula that will color code three cells that are directly above/below each other. The color coding depends on the sum of three other cells that are directly above/below each other, and directly across from the cells to be colored.
This part is easy. The rule is:
Forumula: =SUM(H5:H7)>30
And it applies to:
$E$5:$E$7
However, the issue is that when I copy the cells that are being colored (E's) to three more cells below them for the next batch, the relative formula does not work as expected. It applies the formula on H6:H8 (+1) instead of H8:H10 (+3).
Is there a way to get the relativeformula to work as expected? I hope this was clear enough. I know it's hard to visual a spreadsheet, but ultimately I need the relative forumla to add +3 instead of +1 when it is copied.
Problem:
If I correctly understand, what you are trying to achieve is to have the range E5:E7 formatted strictly based upon H5:H7, then the next three-cell range - E8:E10 - based upon H8:H10 and so on. You can do this by implementing the below solution:
Solution:
Step 1: Setup Columns as Below
Step 2: Implement Conditional Formatting as Below
Explanation:
I have recreated your issue and I see your problem; it was not that obvious until I played around with changing values of different cells in Column H.
Apparently, this has to do with how Excel interprets your instructions (formula) supplied under conditional formatting. To understand this let's first focus on the behavior of cells E5, E6 and E7 as a function of values in Column H.
With the formula =SUM(H5:H7)>30 did you notice that:
E5 format depends upon =SUM(H5:H7),
E6 format depends upon =SUM(H6:H8), and
E7 format depends upon =SUM(H7:H9) and
when you copy the range E5:E7 three cells down into E8:E10, the expected behavior is:
E8 format depends upon =SUM(H8:H10),
E9 format depends upon =SUM(H9:H11), and
E10 format depends upon =SUM(H10:H12)
And this is exactly how the range E8:E10 will behave once the above solution is applied.
A partial answer to your question has to do with your relative formula - =SUM(H5:H7) - under conditional formatting. Using this formula causes $E$5 to use =SUM(H5:H7) to determine its formatting, $E$6 to use =SUM(H6:H8) to determine its formatting, and so on. This ultimately leads to issues with the conditional formatting even before you begin copying the cells down.
EDIT: (piggy-backing off #Bharat Anand's answer)
#Bharat Anand's answer appears to be the best way to accomplish this question.
#Thisisstackoverflow requested clarification (under the accepted answer) and I'm hoping my screenshot below will help.
I set my worksheet up in what I believe is the exact same manner as #Bharat Anand, and it seems that the column letters may have been off. Setting mine up like this made it work correctly.
EDIT: (clarification for future visitors)
I really liked #Bharat Anand's solution, so I wanted to explain how it works (using the images/formulas in the solution as reference):
The calculation in Column I is setup to return a number that will only appear three times, in succession, in Column I; in this way it kind of behaves like a unique identifier, allowing other formulas to reference these values for calculation purposes.
Three times is key for the original poster because they were looking for a range of three cells to be formatted based on a sum of three cells. For example, the formula in Column I can be modified to
=ROUNDDOWN((ROW()-b)/a,0)
where:
a is your desired number of cells to format/sum, and
b is equal to a - 1.
Using the formula in J5 as an example, this SUMIF formula uses I3:I7, which includes two (or b, as setup in my explanation above) rows above and two (b) rows below to decide if I5 equals any of the values found in I3:I7. It's important to include the two rows above and two rows below so that the range overlaps the same three cells to meet the requested requirements.
When I5 finds a match, the formula looks to Column H to sum those rows in H3:H7 where I3:I7 equals I5. In this example, J5, J6, and J7 will each equal 32.
Using the simple conditional formatting formula that was setup, we know that cells in Column E should be highlighted when the corresponding row in Column H is greater than 30. According to the original question, this should be done in ranges that are three (a) rows tall. We already handled for that, so all that was left was to make sure the conditional formatting spanned the data area in Column E.
I'm hoping I don't confuse and/offend anyone with this explanation, but it's how I understand it. I like the proposed solution and explaining it to myself again helps me solidify how it works.

Conditional Formatting of interdependent values in one cell Excel

I am working on a spreadsheet for planning road improvements, there are two aspects. Resurfacing and Surface Dressing these are interdependent values as you can see in the example below. However there is no scenario where both numbers can exceed 100 and I was hoping of finding a way of displaying total percentages of resurfacing and surface dressing in one cell. Ideally with resurfacing on the left of the cell and surface dressing on the right.
Currently I am using conditional formatting on each cell, I know I can store two values in one cell but it doesn't seem possible to use conditional formatting on these cells.
Any Ideas how this can be achieved? Would be much appreciated
I'm not sure which values are which, but combining two results into one cell can be done like this:
="A438 "&A4&" "&A5
and you could replace the A438 with a cell reference :
=A2&" "&A4&" "&A5

Apply Function to every cell in Excel

I have Terz-spectra data from acoustic measurements and I want to calculate the overall level. The values for each Terz-band are in decibel. Therefor the calculation formula is a bit lengthy. It would be L_overall=10*log10(10^(L_a/10)+10^(L_b/10)+10^(L_c/10)+10^(L_d/10)...).
As there are many frequencies, I don't want to write the whole formula by hand. I also don't want to use another column to do the inner calculation (10^(x/10)) before doing the outer calculation (10*log10(x+y+z+...)). So I wonder if there is a function in Excel that allows to apply a calculation on each cell like there is in Matlab for instance (cellfun, arrayfun).
I hope to end up with something similar like L_overall=10*log10(10^(B10:B80/10) which would allow me to do all the calculation in simply one cell.
Addition:
I have forgotten to say that I want the terz-data unaltered. I don't want to change that as I have to use it to plot that spectrum. So ideally I want all the work done in only one cell. I could do that by the lengthy formula, but it would take quite some time to type that for all frequencies.
Of course I could simply use another column and do the math there but that seems also inconvenient.
Actually the formula would be something like this:
=10*LOG(SUM(INDEX(10^(B10:B80/10),)),10)
Or this:
=10*LOG(SUMPRODUCT(10^(B10:B80/10)),10)
It's a bit clunky, but you could do 10^(L_a/10) for one cell, then click and drag the lower right corner to make that run for all cells.
Then create another cell which takes 10*log10 of the SUM of those cells.
If your goal is only to insert a specific formula in a bunch of cells you could use this:
For Each rCell In Application.Selection
rCell.Formula = "=10*log10(10^(L_a/10)+10^(L_b/10)+10^(L_c/10)+10^(L_d/10)...)"
Next rCell
Simply select all the cells in which you want to insert the formula and then run the sub. Make sure your formula is valid.

Conditional Formatting with a formula, highlighting errors

I have a column (I) that is a sum of total hours worked for a month. I'm trying to apply a conditional formatting rule that will highlight cells that equal 0 but aren't blank.
The formula I'm using is:
AND(I2=0,NOT(ISBLANK(I2)))
It highlights most of the 0 values (but not all of them) and it is also highlighting some non-zero values.
I don't know if will help, but this is a sample of what I'm getting:
I had a simmilar problem a few months ago. Mark Fitzgerald pointed out the right direction to me. Times in Excel are all percentages of days. Computers calculate in binary so all those decimals have to be converted to binary before the math operation and the result has to be converted back to decimal.
But decimal places are limited to 15 in Ms Excel. You can check the whole answer here.
I think your issue is the Applies to range (though I am surprised that the Total label is not then coloured blue). It seems to me the formatting is correct but offset by one row. For simplicity, I suggest selecting the entire Total column and applying:
=AND(I1=0,NOT(ISBLANK(I1)))
Or select the range to format starting in the first cell below Total (ie Row2) and apply your formula.
Taking the 'simpler' approach, if you don't want the label formatted you might give it a rule of its own, with No Format Set chosen and make sure it has priority (eg at the top of the list with Stop If True checked).
#Dimitrios has a point (but it seems also a solution) if the values are being calculated.
=AND(I2=0,NOT(ISBLANK(I2)))
Enter the conditional formatting as a formula into the first cell. Click 'Ok'. Then copy the first cell and paste special as "formatting" to the remaining cells.
This will work as you desire.

Resources