Logical calculation in Excel - excel

I need advice/help. I am working on calculation in excel where I have data like mentioned below.
. A B C D E F G H
1| A275 A277 A273 A777 A777 TOTAL A222 GRAND TOTAL
2| 5 7 4 3 4 7 7
Now, I want to count row 2 based on the header.
Here is the condition.
If A1 <> B1 then take A1, if B1 <> C1 then take B1, if C1 <> D1 then C1, so on.
But tricky part is...
If D1<>E1 then D1 else (if E1<>F1 then E1 else (if F1 = "TOTAL" then F1 else(if F1<>G1 then F1)))
In short H2 should have 30 and not 37.
Added comments:------------------------------------
So, Basically if A1<>B1 then take A1 but if A1=B1 then take B1, but then for B1, its a same rule like if B1<>C1 then take B1, but if B1=C1 then take C1 and for C1, same rule. Stopping point will be "TOTAL". Along with these logic I need to check if any cell in row 1 is "TOTAL" then take value for same column. Now this "TOTAL" can be in any cell in row 1.
So from above table my calculation will be 5(A2) + 7(B2) + 4(C2) + 7(F2) + 7(G2) = 30
In this calculation I have not included D2 and E2 as D2=E2 so I took D2, here E2<>F2 so I should have taken E2, but as F2="TOTAL" so I took F2 and not D2 and E2.
I hope this make sense. (Sorry, I know its confusing.)
I have data in more then 100 columns.
Can this be achieved using Macro?
------------------------------------------------------------
Another pain point is data and header are dynamic, so I can't have a fix format. Logic should be in a way that can handle the dynamic data and header.
Any help or suggestion will be greatly appreciated.

I achieved the results you want with this.
Add a helper row. In cell A3 write this formula and drag it to the right:
=IF(OR(A$1=B$1,B$1="TOTAL"),0,1)
Calculate sum in say cell H4 (not H2 because if the formula refers to entire row 2 there will be circular reference):
=SUMIF($3:$3,1,$2:$2)

Related

Formula to add a number to the cell and change that value if it is greater than certain number

In Column A I have numbers from 1 to 30 and in Column B I want to add 10 to the number in column A i.e.
if A1 is 1 I want 11 in B1 and in C1 I want 21 and
if A2 is 2 I want 12 in B2 and in C2 I want 22.
I don't want the numbers in columns B and C to exceed the maximum limit of numbers I have in Column A, in this case that is 30.
I need a formula to achieve this so that none of the cells in column B and C has the number exceeding 30 and if the addition exceeds that I want 30 to be subtracted from it. I tried this with IF but it didn't help as I don't know how to manipulate the current cell after adding the number.
Screenshot of expected results:
I want the number in B Column to be addition of 10 to the number in A Column and it should not exceed maximum number.
Maybe, in B1:
=A1+10-30*(A1+10>30)
and in C1, both copied down to suit:
=B1+10-30*(B1+10>30)
Considering B1, the above can be simplified slightly by rendering (A1+10>30) down to (A1>20).
A1+10 is the basic requirement.
The condition is that where A1+10 exceeds 30, a deduction of 30 should be applied. This can be restated as "where A1 exceeds 20".
(A1>20) returns either TRUE (when A1 is more than 20) and FALSE (otherwise).
What may not have been appreciated by all is that when used as a multiplier, Excel treats TRUE as 1 and FALSE as 0.
So when A1 is less than or equal to 20, nothing is deducted from to A1+10. 30*(A1>20) becomes 30*FALSE (effectively 30*0), which is 0. However, when A1 is more than 20 30*(A1>20) becomes 30*TRUE (effectively 30*1), which is 30.
The formula for B1 is:
=IF(A1+10>MAX($A$1:$A$30),A1+10-MAX($A$1:$A$30),A1+10)
(For C1 just do "Fill Right" from B1.)
Sometimes it's better to use several columns to get to the result:
First I created in D1 =A1+10, then in E1 =MAX($A$1:$A$30).
The $ means that the column or row number does not change when you fill down, so A1 stays fixed to A1 in every cell.
In F1 I created an IF formula: =IF(D1>$E$1,D1-$E$1,D1) which means "IF D1 exceeds the highest value in A1 to A30 THEN subtract that highest value from D1 ELSE just display D1 (=A1+10)"
And if you substitute these values:
(E1): =IF(D1>MAX($A$1:$A$30),D1-MAX($A$1:$A$30),D1)
(D1): =IF(A1+10>MAX($A$1:$A$30),A1+10-MAX($A$1:$A$30),A1+10)
you get the result I mentioned in the first place.

Dragging formulas across - Increment columns by more than 1

I can't seem to find anything similar that's already been asked (they all relate to incrementing row numbers rather than columns)
I'm looking to drag a formula across horizontally and have the columns increment by 2
E.g. B1-A1, D1-C1, F1-E1...
Thanks!
You'll need to have a value in cell A1 and B1 for the following to work.
For my testing I put the number 1 in A1 and B1.
Try this in Cell C1:
=IF(MOD(COUNT($A$1:B1),2)=0,COLUMN(B1),IF(B1<>A1,B1,A1))
Here's what you should see when you drag that formula across:
A B C D E F G H I J K L M N
1 1 2 2 4 4 6 6 8 8 10 10 12 12
And this is what the formula does:
The MOD(COUNT() part of the formula counts the cells to the left of it, and if they are a multiple of 2, the value changes.
I've left the value to change to (the 'new' value) as the COLUMN() number for the cell before, just for example's sake. but you can change this part.
The last IF statement at the end checks if the cell before is equal to the cell before that, (eg. Is CELL C1 equal to CELL B1) and if they are not equal, it will give the cell before as a value (the 'copy' value).

Matching cell from two values

need help here :) I am not excel expert
I have a simple spread sheet with some data and I need to find the matching values from another sheet. Some help would be appreciated.
The data looks like this:
d1 d2 d3 d4 d5
c1 1 5 4 4 3
c2 2 4 9 1 2
c3 4 4 7 8 4
c4 4 7 1 9 2
c5 4 4 7 6 8
So above c1, c2 etc. means Code's and d1, d2 etc. means Dates (future dates).
The numbers between I need to catch in a different spread sheet
example
Code: c2 - User provides the code
Date: d4 - User provides the date
Value: 1 - this value I need to get with formula
Should I attach example file if needed?
If possible to use performance wise formulas as might be quite few of them. Perhaps INDEX/MATCH? if I know how to use it :) but I think also INDEX/MATCH will slow it down a lot, I might be wrong also :)
thank you for your help in advance.
EDIT:
Added screenshot, might help also what is needed.
Assumptions / prerequisites:
Sheet1 cells (A1:F6) is your data / headers from your example
Sheet2 cell B3 is where the user types the code
Sheet2 cell B4 is where they type the date
Sheet2 cell B5 is where the value displays
this would be your formula in Sheet2 C5
=INDEX(Sheet1!A:F,MATCH(B3,Sheet1!$A:$A,0),MATCH(B4,Sheet1!1:1,0))

I am trying to find a formula that will allow me to calculate MAX/MIN without calculating anything after the current row

I want to use the Max/Min function to calculate the minimum number up to the current row, but not count anything after that row. See example below:
A B C
1 10 =MIN(A1:A1) I Want B1 to only count MIN from A1 to A1 from here, then
2 14 =MIN(A1:A2) from here I want B2 to count MIN from A1 to A2,
3 9 =MIN(A1:A3) Then A1 to A3,
4 6 =MIN(A1:A4) etc,
5 14 =MIN(A1:A5) etc.
I could go back and update each row manually, but I have over 700 rows that I want all this to apply to. Is there anyone who can help me with a solution to this problem?
Use this formula in B1, and copy downwards:
=MIN($A$1:$A1)
This is called maintaining referential integrity while writing any excel formula. It should give the desired result on copy towards right or downwards.

How do I link the content of a cell to another worksheet as opposed to the value?

I realize my title doesn't really explain what I'm asking as I don't know the correct terminology but bear with me and I'll explain my question.
I know how to link two cells so that if one changes, the other does as well (i.e. cell C3 is linked to cell E5 by selecting cell C3 and entering "=E5"). But how do I link the information in the cell to another cell?
If my worksheet looks like this:
cell B1 - Grapes, cell C1 - 50
cell B2 - Apples, cell C2 - 60
and I link cell F1 to cell C2 with "=C2". If I change the order of cell B1 and cell B2 to become alphabetical then cell F1 is no longer linked to the value in cell C2 (50) but changes to the value that now becomes cell C2 (60). How do I link cell F1 to the actual value (50) in cell C2 even if the order changes.
Help... Thank you!
Not sure if this is an efficient method; if i correctly understood your question then you can use = to link two cells For example:
Sheet one can look like this
A B C D E
1 1 2 3 4 5
2 5 4 3 2 1
3 1 2 3 4 5
Total 7 8 9 10 11
Sheet two requires cell links so you do:
TotalForA =Sheet1!A4 //output will be 7
TotalForB =Sheet1!B4 //output will be 8
.
.
.
In a simple word you can use = sign and click on whatever cell you're like to get.

Resources