简体   繁体   English

Excel - 创建动态和公式范围

[英]Excel - Create dynamic sum formula range

I am currently using the following formula 我目前正在使用以下公式

=SUM(INDIRECT("'Net "&($A$2)&" "&RIGHT($A48,2)&"'!C4:C21"))

That works out perfectly, but I'm trying to make the range portion of it ( C4:C21 ) dynamic. 这很完美,但我试图让它的范围部分( C4:C21 )动态。

The $A$2 that the formula is referencing is something that someone types in and currently says "May". 公式引用的$A$2是某人输入的内容,目前称为“May”。 The $A48 that the formula is referencing is simply pulling the last 2 digits of the year. 公式引用的$ A48只是拉动当年的最后2位数字。

These are the pieces of the file 这些是文件的各个部分

There are a total of 6 tabs that are significant. 共有6个重要标签。 There are 4 tabs that total up prior years sales for a particular month. 有4个选项卡可以累计特定月份的前几年销售额。 So I have Net May 11, Net May 10, Net May 09, Net May 08. These are the tabs that the Indirect formula is finding. 所以我有Net May 11,Net May 10,Net May 09,Net May 08.这些是间接公式找到的标签。

The last 2 tabs includes the one where this formula exist in (Net May 12) and the tab that the range will need to be based off of (Cust May 12). 最后两个选项卡包括此公式所在的选项(Net May 12)以及该范围需要基于(Cust May 12)的选项卡。 In the Cust May 12 tab Column A is the day, column B the day of the Week, and column C is where we have our sales data. 在Cust May 12选项卡中,A列是日期,B列是星期几,C列是我们的销售数据。 Someone goes in every day and types in the sales for the day. 每天都有人进入销售当天。 So as an example I currently have sales data from 5/1/2012 until 5/18/2012. 举个例子,我目前的销售数据从2012年5月1日到2012年5月18日。 Everything from 5/19/2012 - 5/31/2012 in column C is blank. 从C / C列到2012年5月31日的所有内容都是空白的。 The sales data that currently exist are in C4:C21 , with C22:C34 being blank. 当前存在的销售数据在C4:C21C22:C34为空白。 Because I am comparing prior years sales to this years sales they must be comparable, which is why the formula only uses C4:C21 for all of the prior years sales. 因为我将前几年的销售额与今年的销售额进行比较,所以它们必须具有可比性,这就是为什么公式仅使用C4:C21来进行所有前几年的销售。

I have tried a few things including a CountA and some offsets to try and help me out, but I have been unable to find a solution to making the range dynamic for all of my prior years sales formulas. 我已经尝试过一些东西,包括一个CountA和一些补偿试图帮助我,但我一直无法找到一个解决方案,使我的所有前几年销售公式的范围动态。 I need the formula to simply increment to something like C4:C22 for all of the prior years when someone types in the sales data for the next day in the Cust May 12 tab. 当有人在Cust May 12选项卡中输入第二天的销售数据时,我需要将公式简单地增加到C4:C22的所有前几年。

Your question is not completely clear, but it sounds like you want something like: 你的问题并不完全清楚,但听起来你想要的东西如下:

=SUM(OFFSET(INDIRECT("'Net "&($A$2)&" "&RIGHT($A48,2)&"'!C4:C4"),0,0,COUNTA('Cust May 12'!$C$4:$C$34)))

However, you might want to consider restructuring your data to store it in only one worksheet, say with columns like Year, Month, Day, and Sales. 但是,您可能需要考虑重构数据以仅将其存储在一个工作表中,例如年,月,日和销售等列。 Then, questions like, "What were 2011's month to date sales for May," are easier to answer (particularly with the SUMIFS function added in Excel 2007) like this: 然后,诸如“2011年5月份的销售额是什么”这样的问题更容易回答(特别是在Excel 2007中添加了SUMIFS功能),如下所示:

=SUMIFS(<Sales column>,<Year column>,2011,<Month column>,"May",<Date column>,"<="&DAY(NOW()))

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

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