Creating a column formula in excel, changing only one variable - excel

I have a very basic excel file for looking at the cost of shares and calculating a profit/loss %.
I have the initial purchase price in cell E3 and I have the current share price in F3. I have calculated the percentage profit/loss in G3 by the following formula
=(F3/E3)*100 - 100
What I now want is to be able to apply this formula to the whole G column as I enter a new share price into the F column, it will use E3 as a constant in the formula to calculate daily profit/loss. So the new formula I want is effectively;
=(Fi/E3)*100 - 100
Where Fi = F3, F4, F5, F6 and so on...
I have tried dragging the cell down to extend the formula, which works to an extent but it does not keep E3 constant so I get a divide by zero error.
Any suggestions? Thanks

Start with =(F3/E$3)*100 - 100. The $ is an absolute anchor that tells the formula not to change the 3 in E$3 when filled down.
If there is no value in column F, you can have the result returned as a zero-length string (e.g. "") which will make the cell in column G that holds the formula look blank.
=IF(LEN(F3), (F3/E$3)*100 - 100, "")

Use an absolute reference for E3 in the formula:
$e$3
This will lock the reference if you drag the cell down.

The other way around, if you want to lock the character:
=(F3/$E3)*100 - 100

Related

Minima Elementwise in Excel

I have two columns of data: A and B.
I need a column C with elementwise minima between A and B data.
For instance:
If I put in C:
= MIN ($A$1:$A$3; $B$1:$B$3)
Then I get a single number, the minimum of all data (in our case 1).
What can I do?
Can't you just use
=IF(A1:A3<B1:B3,A1:A3,B1:B3)
Or, a little fancier (depending if available to you):
=BYROW(A1:B3,LAMBDA(arr,MIN(arr)))
This will spill all minima when using Microsoft365.
You were almost there.You just need your formula to be =MIN(A1:B1) at row 1 and then drag down.
Notice there are not $ so we are using relative references. That way you can get minimun value between A and B values at same row, not all values.
Switch between relative, absolute, and mixed
references
In cell C1, you put following formula:
=MIN(A1;B1)
You select cell C1, you put your mouse-cursor in the right-bottom part of cell C1 until the cursor changes in a small cross, you start dragging and you drop once cell C3 is filled.
You will see following formula:
In cell C2:
=MIN(A2; B2)
In cell C3:
=MIN(A3; B3)
As you see, there's no need to use absolute references (the ones with the dollarsigns) you're using.

In excel 365 how to subtract values sequentially but skip empty cells

Not sure how to word this exactly. We have a spreadsheet to keep track of pump runtimes.
We want to subtract the run times in column B and output to Column C so for instance B4-B5 would output .3 to C4. I don't have a problem with basic formula =B4-B5 in C4 and so on down the column. However when I get to B8 I want B7 to subtract B10 and skip the B8 and B9. The reason is that the 25th and 26th was a weekend so values weren't recorded. (these sheets are printed, recorded on location and then brought back to the plant at the end of the month) so what if possible would be a formula I can use?
after using the formula this is what happens:
enter image description here
Try the following formula in C4 and drag down
=IF(B4<>0,B4-INDEX(B5:$B$33,MATCH(TRUE,B5:$B$33<>0,0)),0)
It's checking the cells below for the first non-zero and returning the difference to that value. The key principle here is in the range B5:$B$33. The dollar signs ensure that when you drag the formula down the end of the range you're checking stays at B33, whereas B5 will become B6, B7, etc.
If the column B entries are stricly non-increasing, as per your example, in C4:
=IF(B4,B4-XLOOKUP(9^9,B5:B$33,B5:B$33,B4,-1),0)
and copied down.

Excel formula to Sum 12 rows every 3 rows

I need to make a sum of 12 rows every 3 rows in excel. That is, I need to sum first from C4 to C15, then from C7 to C18, and so on.
You can use OFFSET function for this, also volatile, but shorter!
Assuming first formula in E2 copied down
=SUM(OFFSET(C$4,(ROWS(E$2:E2)-1)*3,0,12))
I prefer this because it explicitly contains all the required information
C4 = first cell to sum,
E2 = first cell with formula,
3 = row increment,
12 = number of cells to sum
The above gives you the sums on successive rows from E2 (or any other chosen cell) down. If you actually want the sum to be shown every 3 cells e.g. on the first row for each sum then that's simpler - try this formula in D4 copied down
=IF(MOD(ROWS(E$2:E2),3)=1,SUM(C4:C15),"")
.......or even easier.....just put this formula in D4
=SUM(C4:C15)
....leave D5 and D6 blank, then select the range D4:D6 and drag down
You can also use the non-volatile INDEX function
=SUM(INDEX(C:C,ROWS($1:1)*3+1):INDEX(C:C,ROWS($1:1)*3+12))
This works because INDEX returns a reference so you can use the normal Ref1:Ref2 notation for a range.
=SUM(INDIRECT("C"&ROW(1:1)*3+1&":C"&ROW(1:1)*3+12))
Be warned that INDIRECT() is a volatile formula... This means that any change made anywhere in the workbook this formula will recalculate and can cause performance issues.

Excel - Find the biggest gap in a set of numbers?

I have a series of numbers
0,1,99,5,5,98,9
They are unsorted and will remain that way.
I cannot use macros.
I want the answer 89 from a formula or an array formula.
89 is the biggest gap (between 9 and 98) in this series when sorted.
I want a formula, no vba, and no sorting my column or row.
I need a formula that sorts the list and subtracts one cell relative to the sorted list and gives the largest difference of the list of differences it creates.
so the list becomes 0,1,5,5,9,98,99
subtracts the current from the previous (na,1,4,0,4,89,1)
and gives me the max 89.
My list is a column of 7 rows.
This formula must be array-entered. In the formula RNG refers to the range where you have entered your numbers, e.g. A1:A7
=MAX(LARGE(RNG,ROW(INDIRECT("1:"&-1+COUNT(RNG))))-
LARGE(RNG,ROW(INDIRECT("2:"&COUNT(RNG)))))
To array-enter a formula, after entering
the formula into the cell or formula bar, hold down
ctrl-shift while hitting enter. If you did this
correctly, Excel will place braces {...} around the formula.
You can see how the formula works by using the Evaluate Formula option on the Formula Auditing tab of the Formulas ribbon.
In brief, the formula works by creating two arrays, sorted in order of size. The "K" value of the LARGE function is an array created by the ROW(INDIRECT sequence. The first returns
{1;2;3;4;5;6}
and the second returns
{2;3;4;5;6;7}
The two arrays of values returned would then be:
{99;98;9;5;5;1}
{98;9;5;5;1;0}
Subtracting one from the other results an array of the differences, and we find the MAX.
MAX(A:A) - LARGE(A:A,2) gives the difference between the largest and second-largest value if your numbers are in column A. Don't put this formula in column A.
Place the values in A1 thru A7 in any order!
In B1 enter:
=RANK(A1,$A$1:$A$7,0)+COUNTIF($A$1:$A1,A1)-1
and copy down thru B7
In C1 enter:
=INDEX($A$1:$A$7,MATCH(ROW(),B$1:B$7,0))
and copy down thru C7
In D2 enter:
=C1-C2
and copy down thru C7
Finally in E1 enter:
=MAX(C:C)
Column B represents the order of the values in column A if they were sorted. Column C contains the values of column A in sorted order. Column D are the differences and E1 gives the desired answer. Here is an example:

In a spreadsheet, I want to copy cells with a negative value onto another cell where there is a floor for negative values

In spreadsheet cell B1, the value is -1200.
I want cell B2 to copy the value of B1 and limit (validate?) it to no less than -800.
I'm using google docs but can also use excel if those functions are not available in google docs.
Edit:
If B1 has the value of 2000, B2 should have the value of 2000.
If B1 has the value of -2000, B2 should have the value of -800
Excel & Google Spreadsheets
=Max(B1,-800)
Excel formula would be pretty easy, probably similar in Google Spreadsheets:
In B2, put this formula:
=If(B1<-800,-800,B1)
This is saying:
If the value in B1 is less than -800, then put the value "-800". Otherwise, use the value from B1. This effectively puts a "floor" or a lower bound on the formula.
You don't need any maths here. I'm using Excel but I think it is pretty similar in Google.
Suppose that B3 holds floor, no constants in formulae :-)
B2 => =if( b1 > $b$3; b1; $b$3)
b3 position is fixed so you can copy the expression

Resources