简体   繁体   English

从动态表计算平均VBA

[英]Calculate average VBA from dynamic table

I ve a table on Excel with the week number and the weight (in Kg.) 我在Excel上有一张表,其中包含周数和重量(千克)

Somebody can insert his weight every day during a week or just once or not at all. 某人可以在一周中每天或每天一次或完全不举重。 I can't manage that. 我没办法 Then my table can literally change. 然后我的桌子就可以改变了。 from zero to 7 even more lines a week (like the yellow side of the image). 每周从零到7行甚至更多(如图像的黄色面)。

What I wanna do is to calculate the weight average per week. 我想做的是计算每周的平均体重。 and then I will have one line for each week, when i got at least one weight (sometimes I won't have any line). 然后当我至少有一个体重时,我每周都会有一条线(有时我什么都没有)。 We can have week without any weight so then I don't want this line at all. 我们可以有一个星期没有任何重量,所以我根本就不需要这条线。 We can also easily have a weight for the week 2 but between the weeks 5 and 6 in the yellow table. 我们还可以轻松得出第二周的权重,但在黄色表格中的第五周和第六周之间。 That would happen if someone insert his weight after others. 如果有人在别人之后增加体重,那将会发生。

How can I say this two weeks are similar, so we calculate the average for this two weight ? 我怎么能说这两个星期相似,所以我们计算这两个重量的平均值?

在此处输入图片说明

I hope it's enough clear with this picture 我希望这张照片足够清楚

Use formula below in Column C to calculate average(assume Week in column A and Weight in column B) 使用下面C列中的公式来计算平均值(假设A列中的Week和B列中的Weight)

=AVERAGEIF(A:A,A2,B:B)

Average Column Copy->PasteSpecial value only, then Remove Duplicates base on Week and the new Average Column 平均列复制->仅粘贴特殊值,然后根据周和新的平均列删除重复项

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

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