简体   繁体   English

将Excel中特定一周中的天中的值相加

[英]Sum the values from the days in a specific week in Excel

So I have some rows of data and some columns with dates. 所以我有一些数据行和一些列日期。 As you can see on the image below. 如下图所示。
I want the sum of the week for each row - but the tricky thing is that not every week is 5 days, so there might be weeks with 3 days. 我想要每一行的星期总和-但棘手的事情是并非每个星期都是5天,所以可能会有3天的星期。 So somehow, I want to try to go for the weeknumber and then sum it. 因此,我想尝试获取周数,然后将其求和。
Can anyone help with me a formular (or a VBA macro)? 谁能帮助我制定公式(或VBA宏)?

I am completely lost after trying several approaches. 在尝试了几种方法之后,我完全迷失了。

表数据 18-May-15 19-May-15 20-May-15 21-May-15 22-May-15 25-May-15 26-May-15 27-May-15 28-May-15 29-May-15 1-Jun-15 2-Jun-15 3-Jun-15 4-Jun-15 WEEK 1 TOTAL WEEK 2 TOTAL 33 15 10 19 18 8 10 15 10 29 16 24 8 26 74 15年5月18日至15年5月19日至15年5月20日至15年5月22日至15年5月25日至15年5月26日至15年5月27日至15年5月28日至15年5月28日2015年6月1日至15年6月2日至15年6月3日至2015年6月4日第1周总计2周总计33 15 10 19 18 8 10 15 10 29 16 24 8 26 74
18 11 8 17 0 6 16 9 16 16 36 9 6 4 55 18 11 8 17 0 6 16 9 16 16 36 9 6 4 55
0 0 1 0 0 1 0 0 1 0 0 3 3 2 8 0 0 1 0 0 1 0 0 1 0 0 3 3 2 8
30 7 4 8 8 11 10 3 0 11 3 4 5 6 18 30 7 4 8 8 11 10 3 0 11 3 4 5 6 18
0 0 0 11 0 0 0 1 0 7 8 1 1 2 12 0 0 0 11 0 0 0 1 0 7 8 1 1 2 12
1 1 4 0 5 1 6 2 1 4 2 4 5 4 15 1 1 4 0 5 1 6 2 1 4 2 4 5 4 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
52 27 22 36 23 15 32 26 27 49 54 37 19 34 144 30 50 25 21 34 12 33 32 26 43 54 43 18 32 147 0 0 1 0 3 0 0 0 0 0 0 0 0 0 0 52 27 22 36 23 15 32 26 27 49 54 37 19 34 144 30 50 25 21 34 12 33 32 26 43 54 43 18 32 147 0 0 1 0 3 0 0 0 0 0 0 0 0
29 5 3 4 4 1 1 2 4 4 3 4 2 3 12 29 5 3 4 4 1 1 2 4 4 3 4 2 3 12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 1 10 9 0 0 0 0 0 1 1 2 0 0 0 4 1 10 9 0 0 0 0 0 1 1 2
1 2 0 0 0 0 0 1 3 0 0 0 2 2 4 1 2 0 0 0 0 0 1 3 0 0 0 2 2 4
15 29 5 17 16 4 18 20 12 28 25 22 4 23 74 15 29 5 17 16 4 18 20 12 28 25 22 4 23 74
11 15 11 3 15 7 11 9 5 12 18 10 5 7 40 11 15 11 3 15 7 11 9 5 12 18 10 5 7 40
1 0 2 1 1 0 0 1 8 1 4 3 2 0 9 1 0 2 1 1 0 0 1 8 1 4 3 2 0 9
3 6 7 0 2 1 4 2 1 2 7 8 7 2 24 3 6 7 0 2 1 4 2 1 2 7 8 7 2 24
21 21 21 21 21 22 22 22 22 22 23 23 23 23 21 21 21 21 21 22 22 22 22 22 23 23 23 23

Using SUMIF is one way. 使用SUMIF是一种方法。 But you need to get your references straight in order to make it easy to enter. 但是,您需要直接获得参考文献以便于输入。

Note in the diagram below, the formula: 注意下图中的公式:

=SUMIF(Weeknums,M$1,$B2:$K2)

where weeknums is the row of calculated Week Numbers. 其中weeknums是计算出的周数的行。

在此处输入图片说明

Also note that the column headers showing the Week number to be summed could be made more explanatory with custom formatting: 还要注意,使用自定义格式可以使显示要累加的星期数的列标题更具解释性:

I know you've already accepted an answer but just to show you: 我知道您已经接受了答案,只是为了向您展示:

If you transposed your data you would then be able to utilise the pivot tables 如果您转置了数据,则可以使用数据透视表

原始数据

You could set up a calculated field to calculate exactly what you wanted (and depending on how you sorted/grouped the date you could sort this by weeks, months, quarters or even years 您可以设置一个计算字段来准确计算您想要的内容(并根据您对日期进行排序/分组的方式,可以按几周,几月,四分之一甚至几年来进行排序

计算场

You would then get all of your final values displayed in an easy to read format grouped by whatever you want. 然后,您将以易于阅读的格式将所有最终值显示出来,并根据需要进行分组。 In my opinion this is a lot more powerful solution for the long run. 在我看来,从长远来看,这是一个更强大的解决方案。

结果

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

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