简体   繁体   English

基于另一个单元格中的值的动态范围

[英]Dynamic range based on values in another cell

I will lay out the question I currently have.我将列出我目前遇到的问题。 I have an excel sheet in which column A is Date-type data, Column F is returns data, say returns of S&P500 (for examples sake).我有一张 excel 表,其中 A 列是日期类型数据,F 列是返回数据,比如标准普尔 500 指数的回报(例如)。 I have two cells, say G1 and G2, which have arbitrary start and end dates, respectively.我有两个单元格,比如 G1 和 G2,它们分别具有任意的开始日期和结束日期。

I want to be able to dynamically calculate the standard deviation of the returns data (Column F), with the start date and end date of the range of the standard deviation being equal to cells G1 and G2 respectively.我希望能够动态计算返回数据(F 列)的标准偏差,标准偏差范围的开始日期和结束日期分别等于单元格 G1 和 G2。 Therefore, as I change cells G1 and G2, it will calculate a different standard deviation, as the range of the function will change.因此,当我更改单元格 G1 和 G2 时,它将计算不同的标准偏差,因为 function 的范围会发生变化。

I have already tried using an offset function, but have had difficulty in making the range dynamic in the sense that, if I just had a set start date, and was interested in changing the number of days to include in the range, I could do that.我已经尝试过使用偏移量 function,但很难使范围动态化那。

The formula would look something like = STDEV.S(OFFSET(A4,1, 5, G3, 1)) where G3 is the number of days looking forward I want to include in the range.该公式类似于 = STDEV.S(OFFSET(A4,1, 5, G3, 1)) 其中 G3 是我希望包含在该范围内的预期天数。

This does not allow me to change the dates in interest as I please.这不允许我随意更改感兴趣的日期。

If I haven't explained something enough, please let me know.如果我解释得不够清楚,请告诉我。

Best,最好的,

If your data or first date in Column A starts from Row 4 , then如果 A 列中的数据或第一个日期从第 4 行开始,则

try replace the first 1 in your OFFSET function to the following:尝试将您的偏移量 function 中的第一个1替换为以下内容:

=MATCH($G$1,$A$4:$A$100,0)-1

Replace $A$4:$A$100 with the actual range of the dates in your Column A,$A$4:$A$100替换为 A 列中日期的实际范围,

Then your formula will be something like:那么你的公式将类似于:

=STDEV.S(OFFSET(A4,MATCH($G$1,$A$4:$A$100,0)-1, 5, G3+1))

or或者

=STDEV.S(OFFSET(A4,MATCH($G$1,$A$4:$A$100,0)-1, 5, (G2-G1)+1))

The logic is to use MATCH function to return the starting row position based on the start date from cell G1 .逻辑是使用MATCH function 根据单元格G1的开始日期返回起始行 position 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM