Incrementing row references in Excel formulas - excel-formula

In my excel sheet I need to expand my vertical range by one row. For instance, I need my C column to look like this (after 14th row):
C14--to be--> =NPV(B1, B9, B14:B14)
C15--to be--> =NPV(B1, B9, B14:B15)
C16--to be--> =NPV(B1, B9, B14:B16)
and so on.
What is the proper way of relative addressing for cell C14?

Make everything but the last component of the range absolute:
=NPV($B$1, $B$9, $B$14:B14)

Related

Excel worksheet need increment

I am working on two worksheets to calculate the profit of the products. So what I have to do it take the cell from the main sheet (D3) and take another value and add it to the D3. The following is the formula I got(=D3+'Profits '!B3+'Profits '!B4+'Profits '!B5+'Profits '!B6). the problem is when I scroll down to calculate D4, D5, D6 the cell from the Profits sheet also increases. I only want the main sheet to increment and remain the same for the other sheet
example
=D3+'Profits '!B3+'Profits '!B4+'Profits '!B5+'Profits '!B6
=D4+'Profits '!B3+'Profits '!B4+'Profits '!B5+'Profits '!B6
=D5+'Profits '!B3+'Profits '!B4+'Profits '!B5+'Profits '!B6
How can I do that to achieve this formula in excel.
Thank you in advance.
Precede a row or column address with a $ sign to make it absolute, like $B$6.
An absolute reference will not change when copied to another cell. Rows and columns can be made absolute independently. $B6 will not change when copied left and right but will change when copied vertically. B$6 won't change when copied up or down but will adjust when copied left or right.
$B$6 will be unchanged during any copying.

Indexing Cell Reference

I need a way to reference Cell A1 in Cells C1:C16, then B2 in Cells C17:C32, and so on for a few thousand rows, so manual data entry would be very tedious. I am able to get the proper row to reference using the fomula:
=ROUNDDOWN(1+(ROW()-1)/16,0)
This formula produces the number 1 for rows 1:16, the number 2 for rows 17:32 etc.
But once I have that row number, I am not sure how I can reference the contents of column A in the row determined by a formula.
I was trying something like:
=$A(ROUNDDOWN(1+(ROW()-1)/16,0))
so that once the formula is evaluated, it becomes $A# where # is the intended row number, but obviously that is not syntax that excel recognizes. Any ideas on how to go about getting the correct cell references would be appreciated.
The same answered through Comment by #chris neilsen and the same accepted by #User247365
Here your go for an answer!
Feed the calculated row into
=INDEX($A:$A, row, 1)

Changing countif range automatically

I'm using this formula to count the word red in the last 30 days but the range is not changing when a new row is added at the bottom.
How can I change the formula so when a new row is added at the bottom the range is adjusted automatically? The quantity of rows to check is always 30.
=COUNTIF(D2433:D2463, "Red")
Another technique is using a dynamic named range:
Formula > Name Manager > New: Give a Name first and then insert the following formula into Referes to field. Also see the picture.
=INDEX(Sheet1!A:A,1):INDEX(Sheet1!A:A,INDEX(MAX((Sheet1!$A:$A<>"")*(ROW(Sheet1!A:A))),0))
This should give you a range like $A$1:$A$300 depends where the last non-empty cell is.
Now in the cell that you want to evaluate, add this formula:
=COUNTIF(rng,"red")
Please note rng is the named range that you should change to the name you want to use.
This will find the last cell and even work for blank cells. Try and let me know if you have any question.
Use the following:
=COUNTIF(OFFSET($D$2433,0,0,30,1),"Red")
The references you are using $D$2433 till $D$2463 count 31 if you need 31 change in the above formula 30 to 31
Offset will start in $D$2433 and count the rows down in the same column
Countif will count if Red
Update
If in column D you insert only Data to be counted, you can use :
=COUNTIF(OFFSET(INDIRECT("$D$"&MAX(IF($D:$D<>"",ROW($D:$D),0))),0,0,-30,1),"Red")
This is an array formula press Ctrl+Shift+Enter instead of just Enter
The new formula will find the last non empty row in column D and Indirect will correct the formula automatically
You need a relative cell reference. You can do this with the
=OFFSET()
function.
=COUNTIF(INDEX(D:D,AGGREGATE(14,6,ROW(D:D)/--((D:D)<>""),1)-30):INDEX(D:D,AGGREGATE(14,6,ROW(D:D)/--((D:D)<>""),1)),"Red")
Conditions:
There all rows beneath the last row must be blank
There cannot be any blank row within the last 30 row or your count may be off.
This is an array like function. If you use full range references it checks 1048576 cells each time the aggregate function references the full column range. As such if you use the formula a lot you can bog down your computer, if you are only using it a couple of time you will probably be ok.

How to make excel only change some cell values when auto filling

I have a formula for calculating a sum based on dates.
=SUMIF('Daily Expense'!A:A,CONCATENATE("2/",B1,"/2017"),'Daily Expense'!B:B)
Now I want all the columns of a row to have the same formula with only 1 change like
=SUMIF('Daily Expense'!A:A,CONCATENATE("2/",C1,"/2017"),'Daily Expense'!B:B)
For the next column and D1 for the next one and so on.
When I use the auto fill method of dragging the mouse from the bottom right it fills the function and changes it to
=SUMIF('Daily Expense'!B:B,CONCATENATE("2/",C1,"/2017"),'Daily Expense'!C:C)
All I want to change is the cell value in the concatenate function not the others.
Any idea how to do this?
A:A is a relative reference which will update as you move the formula. You just need to change it to absolute, like $A:$A:
=SUMIF('Daily Expense'!$A:$A,CONCATENATE("2/",B1,"/2017"),'Daily Expense'!$B:$B)
Now when you autofill it will only update the B1 reference.

setting a dynamic cell reference in excel

I have a sheet setup that calculates totals. Easy enough if the data is already there but not if adding new data. So what I would like to be able to do is to not specify a specific end cell for the sum formula but let it update as more columns are added.
How can I do this with =SUM(m4:m?)
Suppose you need totals for data in M4:M10.
To make just open-ended range, you can make lower limit "too far": =SUM(M4:M100000).
Alternatively you can make it as =SUM(M:M) - SUM(M1:M3)
But this is not applicable when you need to have totals value just below the set of values. In this case you have 2 ways.
Using Excel embedded features
The formula will look like his: =SUM(M4:M10). If you insert a new row between M4 and M10 (for instance, select row 5, right-click, insert row), you formula will be automatically adjusted to =SUM(M4:M10).
The problem may happen if you want to insert a new value above the first row (select row 4, right-click, insert row) or below the last row (select row 11, right-click, insert row). In these cases totals formula will not be adjusted.
Possible workarounds:
For the "above first row" issue, I prefer to make some empty row above and hide it. In our case I would hide row 3 and make totals formula look like =SUM(M3:M10), so, when you insert a new row above the first row, in fact you insert a row to the middle of the table, and totals formula will be adjusted.
For the "below last row" - leave empty row below; but in this case you cannot hide it; just make it different color and make some remark like "new values shall be inserted ABOVE this line".
INDEX()
Interesting trick is using INDEX() function, which returns a reference to a cell in the array. For our case, the array can be the whole M row and, the index - row number.
For the "above first row" issue make totals formula like this =SUM(INDEX(M:M;4):M10). So, calculation will always start at row 4, even if some lines will be added/deleted.
"below last row". Suppose you have your "totals cell" in M13 and you want to have totals for all value between M4 and the "totals cell". The formula may look like =SUM(M4:INDEX(M:M;ROW(M13))) or, considering "above first row" case: =SUM(INDEX(M:M;4):INDEX(M:M;ROW(M13)))
Hope this helps
Sum(m4:m?) insinuates that you are looking to add more rows as opposed to adding column data.
If you want to auto sum a row data you can use something like:
=SUM(OFFSET(A1;0;0;COUNT(A:A);1))
However this assumes that the data is contiguous in each cell and also empties are not allowed for 0 because it gets the count wrong.
However: You could also define a table for the data range. If you add data to columns/rows that are in that data range, they will be included in the adjusted formula automatically - very nice indeed.
Select your data range, then Select Insert:Table. This will give your table a name like Table1.
Your sum function would now be adjusted to look something like:
=SUM(Table1)
Now, as you add to the range, the table resizes, and your function just works.
The beauty of using a table, is that if you add data to the row/column immediately after the table it resizes and includes that range. This is hard to do without a table. You can also change the format of the table, or make the format colours invisible but you're probably better off with some format to show the data area of the table to the user.
You can compute the last row containing a number using this formula:
=LOOKUP(2,1/ISNUMBER($J:$J),ROW($J:$J))
This formula would not have a problem if you had text or blanks in the range.
You could then define that formula as a Defined Name
and use the formula:
=SUM(OFFSET(J4,0,0,LastRow-3))
to Sum the range. Note the -3 at the end to compensate for the first cell being in row 4.
Another option would be to just set your range to a fixed range that you can guarantee will be larger than any range you might actually use:
=SUM(J4:J1000)
You can use a counta to find the max row number. Then pushing that into an indirect will give you the range you need.
=SUM(INDIRECT("A1:A" & COUNTA(A1:A1000000);TRUE))
Assumptions:
Data are on column A
Data start from first row
There are no blanks rows

Resources