I was asking myself whether it is possible to add numbers to cell references which are used for formulas in Excel.
In my case I have the formula
=VAR.P('Excess Return'!E2:E22)
which obviously gives me the variance for the numbers ranging from E2 to E22.
Now I want to drag down the formula for all other cell and therefor i want something like
=VAR.P('Excess Return'!E2:E22+D3)
with the number 4 in the Cell D3 for example.
Now Excel should do
=VAR.P('Excess Return'!E2:E26)
but it doesn't and returns "#NAME?"
Any idea on how I can solve this problem?
Any help is greatly appreciated.
EDIT for clarification
My example wasn't really what I actually meant. Sorry for that.
So I have two columns with numbers E and F. In column G there is the formula.
G2 = VAR.P('Excess Return'!"E"&E2:"E"&F2)
E2 = 2
F2 = 22
which then should result in
G2 = =VAR.P('Excess Return'!E2:E22)
So I want to insert the numbers stored in column E and F into the cell reference for the variance function.
If the size of your referenced range is not supposed to change while dragging down, you can probably do what you want by properly using relative and absolute cell references
If you want to change your reference based on the value of another cell, however, you probably need an indirect reference.
Solving your example with INDIRECT():
=VAR.P(INDIRECT("'Excess Return'!E"&E2&":E"&F2))
Another way to reference indirectly - preferable because it is less volatile and causes less recalculations:
=VAR.P(INDEX('Excess Return'!E:E,E2):INDEX('Excess Return'!E:E,F2))
Thanks #DirkReichel for pointing out that alternative.
Related
It's probably a simple problem, but I did not even know the keywords to google it ;/. Let's say I have this data :
Now I also have this litle formula:
If I know drag the C cell to the right, Excel will attempt the following caluclation:
=2+B1
What I want him to do is to attempt this calculation
=2+A2
Of course the easiest solution would be to store my initial data in one row instead of 1 column, but it is really inconvenient for me. Thanks for any help
You can use the indirect() method to reference a cell by it's "String identifier", i.e. "A3". When filling out to the right, use CONCATENATE() and COLUMN() to create your String identifiers {A1,A2,A3,A4,A5...} as required:
=2+INDIRECT(CONCATENATE("A";COLUMN()-2))
This will result in the following:
Side-Node: If you want this for some x/y-Grid-Generation, you can also be lazy,
and just insert =COLUMN() for every cell from "A1 - Z1" and ROW() for every cell from "A2 - A24".
(Or even avoid these at all and directly perform your actual calculation by using column() and row() as replacement for your x/y.
You may try using a combination of the INDIRECT and COLUMN functions:
=2+INDIRECT("A"&(COLUMN()-2))
You would paste the above formula into cell C1, and then drag across to the right however many columns/rows you wanted to cover.
This would result in the following:
This works because COLUMN()-2 returns 1 for the C column, 2 for the D column, and so on. Therefore, the formula will be calling INDIRECT on A1, A2, etc. for column C, D, and so on.
In general, if you want relative references to move down as cells are dragged to the right, you can use this:
Instead of:
= 2+A1
Do:
= 2+INDEX($A:$A,COLUMN()+<offset>)
Where <offset> is whatever offset you need. The offset will change depending on which column the starting formula is located in.
INDEX should be preferred over INDIRECT because INDIRECT is volatile (must recalculate after any change to the workbook) but INDEX is not (only recalculated when one of the inputs the formula, in this case $A:$A, changes).
Let's say I have a range in Excel that looks like this:
Simple Range
X 1
D 2
F 3
R 4
E 5
S 6
T 7
V 8
Q 9
And I want to take the sum of three specific values in that range. Let's say the values that correspond with E, X, and F.
I might write a formula like this:
=B5+B1+B3
That's great and gives me a value of 9 (5+3+1).
Then I decide I want to clean up my range a bit, and put col A in alpha order. When I sort the range, my relative cell references don't move in Excel 16.
The formula I wrote will remain =B5+B1+B3, which now reference the values related to D,F, and R (since the whole range has been sorted)
This seems to run absolutely counter to the whole core concept of relative cell references. I would expect that sorting, like insert/delete rows, drag/drop, or copy/paste moves and reorders the cells in the range, and so the formula that references those cells should also be altered.
In other-words, I would expect my formula to become
=B2+B9+B3
My question is why?
(It's worth noting at this point the solution to this problem is to use VLOOKUP like:
=VLOOKUP("U",$A$1:$B$8,2,FALSE)+VLOOKUP("T",$A$1:$B$8,2,FALSE)+VLOOKUP("Z",$A$1:$B$8,2,FALSE)
I don't need help with a technical fix so much a philosophical adjustment)
I understand that a verbose equation like the VLOOKUPs above is a much more reliable way to follow wanted values in a range that endures sorting. However, I feel I understand the philosophy of relative cell references well, and I would expect them to move with the sort!
What's more, if I were to do something like change the formatting on B5, B1, and B3, and then sort the range, that formatting would "stick" to the cell. So why does sorting uphold the metaphor of "shifting cells" as it applies to formatting, but use the metaphor of "overwriting cell" when it applies to relative references in a formula.
What am I missing?
I made cell A1 equal 1.39139
Made cell B1 equal 1.40596
Made cell C1 a formula =(A1-B1)*10000
Copied cell C1 and pasted it by value into cell D1
In cell E1 I wrote manually the real result of the calculation, which is -145.7 (you can try using a calculator).
In cell F1 I made an if statement to compare the results of E1 and F1: =IF(E1=D1,"equal","not equal")
The result is "not equal".
**I want to know how to copy and paste a formula and make sure its pasted result will be exactly the same. keep in mind that I don't want to use =round() formula because I need a solution for many numbers, and I can't use round() for each cell with different number of digits.
As already pointed out, this is because of Excel's floating point precision.
You are correct that (1.39139-1.40596)*10000 is equal to -145.7. However, I tried typing this into Excel to see what it actually produced and I found the following. If you highlight your cell C1 and press F9 on the keyboard you will see that Excel actually computes this value as -145.700000000002.
I know you said you don't want to use ROUND but, aside from avoiding floating point numbers altogether (i.e. only using integers), I think ROUND is your only option.
I suggest that you determine what is the maximum number of digits after the decimal you will ever need in your sheet, and incorporate ROUND(<number>,<max digits>) into all formulas as necessary.
i.e. instead of using =(A1-B1)*10000, you should type =ROUND((A1-B1)*10000,5) (for example to round to 5 digits) which would return the value of exactly -145.7. I hope this helps, or if nothing else, I hope this at least shed light on what is causing this.
I have the following summation formula:
In text:
SUM (k*1.07^n), n=c1 to n=c2
k, c1 and c2 are 3 single numbers, specified in respective individual cells.
k is a constant, but c1 and c2 should be dynamically changeable.
Is that possible to do in Excel, and if so, how?
I know it's a fairly simple mathematical concept so I'd be surprised if Excel couldn't do it, but I haven't been able to find the formula myself. I've tried SUM and SUMIF, but from what I understand, that requires me to fill a whole range of cells each time I want to calculate something. I've also found some suggestions to use arrays in Excel, which I understand is automatically filling cells - which is at least a little more automated - but I'd rather not fill extra cells, if it's possible.
As a sidenote, I read Excel's accuracy is bad in high digit numbers, but as long as the first 5 digits are correct, it'll be accurate enough for my purpose.
With k, c1, and c2 in A1, B1 and C1 respectively, use the following formula:
=A1*SUMPRODUCT(1.07^ROW(INDIRECT(B1&":"&C1)))
Regards
Here is my problem:
I have a cell (V4) containing the value 444. I want to use this value in the formula of another cell (M12) in the following way. I want the formula to be equivalent to =MIN(L12:L444) but instead of 444 I want to refer to cell V4 which contains the value 444. But when I type in =MIN(L12:L(V4)) it obviously doesnt work so how do I do it? Sorry if I didn't explain it very well. :S
Would this work for you:
=MIN(L12:INDIRECT("L"&$V$4))
From: Excel - INDIRECT and Using the value in a cell as a cell reference in a formula?
INDIRECT will work and is closest to the solution you described, but I prefer OFFSET, which uses proper references. (For example, if you insert a column in the sheet before L, INDIRECT will break while OFFSET will just update its reference as expected.
Two ways to go with OFFSET:
1 - Start at L$1 and go down $V$4-1 rows. (This will work with $V$4 as you've defined it now.)
=MIN(L12:OFFSET(L$1,$V$4-1,0))
2 - In $V$4, provide the height of the range you want.
=MIN(OFFSET(L12,0,0,$V$4,0))
It's hard to make suggestions without more context, but I'm sure you can tweak one of these patterns to meet your needs.
I am not sure if you are trying to include all of the values in 1 column and then on non-contiguous cell. If so, it should look like = Min(L12:L444,V4) . The L12:L444 looks at the value in every cell in the L column from 12 - 444.
So you can check individual cell (A3, D15, Q54) with commas, or a range of cells (A3:Z54) with a colon. Or a range and a specific cell like above =Min(L12:L444, V4).