Prevent cell numbers from incrementing in a formula in Excel - excel

I have a formula in Excel that needs to be run on several rows of a column based on the numbers in that row divided by one constant. When I copy that formula and apply it to every cell in the range, all of the cell numbers increment with the row, including the constant. So:
B1=127
C4='=IF(B4<>"",B4/B1,"")'
If I copy cell C4 and paste it down column C, the formula becomes
=IF(B5<>"",B5/B2,"")
=IF(B6<>"",B6/B3,"")
etc.
when what I need it to be is
=IF(B5<>"",B5/B1,"")
=IF(B6<>"",B6/B1,"")
etc.
Is there a simple way to prevent the expression from incrementing?

There is something called 'locked reference' in excel which you can use for this, and you use $ symbols to lock a range. For your example, you would use:
=IF(B4<>"",B4/B$1,"")
This locks the 1 in B1 so that when you copy it to rows below, 1 will remain the same.
If you use $B$1, the range will not change when you copy it down a row or across a column.

In Excel 2013 and resent versions, you can use F2 and F4 to speed things up when you want to toggle the lock.
About the keys:
F2 - With a cell selected, it places the cell in formula edit mode.
F4 - Toggles the cell reference lock (the $ signs).
Example scenario with 'A4'.
Pressing F4 will convert 'A4' into '$A$4'
Pressing F4 again converts '$A$4' into 'A$4'
Pressing F4 again converts 'A$4' into '$A4'
Pressing F4 again converts '$A4' back to the original 'A4'
How To:
In Excel, select a cell with a formula and hit F2 to enter formula
edit mode. You can also perform these next steps directly in the
Formula bar. (Issue with F2 ? Double check that 'F Lock' is on)
If the formula has one cell reference;
Hit F4 as needed and the single cell reference will toggle.
If the forumla has more than one cell reference, hitting F4 (without highlighting anything) will toggle the last cell reference in the formula.
If the formula has more than one cell reference and you want to change them all;
You can use your mouse to highlight the entire formula or you can use the following keyboard shortcuts;
Hit End key (If needed. Cursor is at end by default)
Hit Ctrl + Shift + Home keys to highlight the entire formula
Hit F4 as needed
If the formula has more than one cell reference and you only want to edit specific ones;
Highlight the specific values with your mouse or keyboard ( Shift and arrow keys) and then hit F4 as needed.
Notes:
These notes are based on my observations while I was looking into this for one of my own projects.
It only works on one cell formula at a time.
Hitting F4 without selecting anything will update the locking on the last cell reference in the formula.
Hitting F4 when you have mixed locking in the formula will convert everything to the same thing. Example two different cell references like '$A4' and 'A$4' will both become 'A4'. This is nice because it can prevent a lot of second guessing and cleanup.
Ctrl+A does not work in the formula editor but you can hit the End key and then Ctrl + Shift + Home to highlight the entire formula. Hitting
Home and then Ctrl + Shift + End.
OS and Hardware manufactures have many different keyboard bindings for the Function (F Lock) keys so F2 and F4 may do different things. As an example, some users may have to hold down you 'F Lock' key on some laptops.
'DrStrangepork' commented about F4 actually closes Excel which can be true but it depends on what you last selected. Excel changes the behavior of F4 depending
on the current state of Excel. If you have the cell selected and are
in formula edit mode (F2), F4 will toggle cell reference locking as Alexandre had originally suggested. While playing with this, I've had F4 do at least 5 different things. I view F4 in Excel as an all purpose function key that behaves something like this; "As an Excel user, given my last action, automate or repeat logical next step for me".

TL:DR
row lock = A$5
column lock = $A5
Both = $A$5
Below are examples of how to use the Excel lock reference $ when creating your formulas
To prevent increments when moving from one row to another put the $ after the column letter and before the row number. e.g. A$5
To prevent increments when moving from one column to another put the $ before the row number. e.g. $A5
To prevent increments when moving from one column to another or from one row to another put the $ before the row number and before the column letter. e.g. $A$5
Using the lock reference will prevent increments when dragging cells over to duplicate calculations.

Highlight "B1" and press F4. This will lock the cell.
Now you can drag it around and it will not change. The principle is simple. It adds a dollar sign before both coordinates. A dollar sign in front of a coordinate will lock it when you copy the formula around. You can have partially locked coordinates and fully locked coordinates.

Related

Excel formula to copy cell value without keeping reference to source cell

In my excel sheet, I need to copy the value of a cell A1 to another cell B1. When I change the value in cell A1, B1 should keep its original value.
Basically what would happen if you copy > paste special > Values
However, I cannot do this manually with mouse or keyboard input. I also cannot use macros/VBA.
Does a formula exist in excel that accomplishes this same task?
I tried playing around with =VALUE(A1) and =concat(A1) but these formulas all contain references to cell A1 and the result changes as soon the value in A1 changes.
As already mentioned in the comments, what you are asking can be done but at the cost of an error message and without the possibility of further calculations of the 'copied' cell, by letting the 'copying' cell refer to itself.
As shown in the screenshot above, the value returned in F3 is the value of E3 or itself, depending on the selection in F5.
Selecting "No" (or anything else but "Yes") in F5 and thereby having F3 refer to itself will show an error message, but the value it had will stay, even when saved and closed. However, no further calculation can be conducted on that cell:
Lastly, this solution is probably unstable.

how can I sum every n cells in Excel?

In Excel I need to just add up some cells across a row, like this:
=sum(A1+D1+G1+J1)
As you can see, it's just every third cell. I have to do this often so I'd love an equation I could copy and paste.
Is there a way to say "sum every third cell from A1 to V1"?
You can use an array formula
=SUM(IF(MOD(COLUMN(A1:V1),3)=1,A1:V1,0))
Confirm with Ctrl, Shift and Enter and curly brackets will surround the formula.
Btw, all this stuff is online.

How to avoid manually entering this formula in Excel

I'm trying to calculate a value called, "additional throughput". It is calculated by subtracting the base case module's throughput from a new module's throughput.
In the sheet below you can see that for the third row down (has a blue box in it), that the additional throughput is calculated by the formula "=T6-T4".
The problem is that when I click on this box and drag it down to apply the same formula to the other rows, I want the formula to become "=T7-T4" for the next row. Instead it becomes "=T7-T5". I tried to select multiple cells (where the formula was manually entered) before dragging down so it could recognize that the T4 doesn't change, only the first part. However, that didn't work.
In Excel you can use $ signs before the column or row references to make those references "absolute" (rather than "relative"). For example if you use =A$1 then the 1 doesn't change when you copy down. If you use =$A1 then the A doesn't change when you copy across. If you use =$A$1 then neither changes whichever way you go.
So for your case you need to use
=T6-T$4
when you copy that down T$4 doesn't change
You have to make the cell address of T4absolute by pressing F4, so it becomes $T$4. When you then copy the formular to other places T4 will keep its absolute address.
I figured it out.
You put a $ symbol in front of the row and column you want to not change. This is referred to as an absolute reference.
Found out how to do it here:
How do I change an Excel relative cell to an absolute cell?

Excel - Sum contents between headers if a string is found

I'm trying to do the following: if it finds a letter "A" in the 3rd column, sum all the values of the 2nd column (that are in the same line as the "A"), but, between the headers is a single range.
I've tried using arrays and other type of functions, but I'm not getting anywhere..
The tricky part is that the sum must restart when it finds a new header.
There are no gaps between headers.
Thanks everyone!
PS. Actually, there aren't any 'blocks' without an "A", like the one you can see below the 2nd header. I've already filtered and deleted those.
You could try entering this in cell D2 and fill down:
=IF(LEN(C3)<>1,SUMIF($C$2:C2,"A",$B$2:B2)-SUM($D$1:D1),"")
... but if you have many rows it would be preferable to fill simple SUMIF formulas using code. One way to do this is to press Alt+F11 to access the VB code window, then enter in the immediate window this line and press enter:
[E1:E13]=[IF(LEN(OFFSET(C1:C13,1,0))<>1,"=SUMIF(C"&LOOKUP(ROW(C1:C13),ROW(C1:C13)/(C1:C13="H3"))+1&":C"&ROW(C1:C13)&",""A"",B"&LOOKUP(ROW(C1:C13),ROW(C1:C13)/(C1:C13="H3"))+1&":B"&ROW(C1:C13)&")","")]
This enters these three formulas in the cells shown and leaves the remaining cells blank.
E4 =SUMIF(C2:C4,"A",B2:B4)
E9 =SUMIF(C6:C9,"A",B6:B9)
E13 =SUMIF(C11:C13,"A",B11:B13)

How to Set formulas for a range of cells in Excel

I have started learning Excel more recently. I am learnng to use Excel Formulas. In Cell
C8 I type the formula = (C8*DividedShares)/TotalShares. Divided Shares and Total Shares are named cells and I have plugged in values 12345 and TotalShares as 21000. Now I want to apply this formula from cell C9 to C1000. What is the quickest way to do it using keyboard keys.
Once the formula is written, copy the cell, pressing Ctrl-C. Then you need to select the range you want to fill with the formulas (with the keyboard, keep Shift pressed and go down with the arrow key for a while). Then, without unselecting, push enter.
Alex is quite right. Alternatively, if this was an action that had to be repeated, the process could be written in VBA and a key combination assigned to call the code.

Resources