Excel - 从单元格范围创建图表,同时排除空值?

发布于 2024-11-18 10:30:01 字数 620 浏览 2 评论 0原文

我有这张 Excel 工作表,其中基本上包含大量数据。 现在,此 Excel 工作表通过导入数据的宏动态更新。因此数据可能会发生变化,这意味着某些单元格可能会被填充,而其他单元格则不会。

因此,我在工作表 2 中从 A2:A60 到 M2:M60 的每个单元格中都有这个公式,基本上如下所示:

=IF(Sheet1!E2<>0;Sheet1!A2;"")

意思是,如果我所在行的单元格 E2 为 0,则新电子表格中复制的值没什么。下一行也是如此:

=IF(Sheet1!E3<>0;Sheet1!A3;"")

重复直到第 60 行。

现在,我要做的是选择范围 A2:A60 并将该数据插入到图表中。但问题是,图表添加了没有值的单元格。我想将其从图表中排除,而不必更改图表的范围。可以在图表选择中使用公式吗?或者我必须使用宏?

编辑:现在,当我基于 A2:A60 创建图表时,图表看起来像这样。请注意,由于上述公式,只有 A4:A17 实际上具有任何值,其他值没有任何值。

带有不需要的(空)值的图表。

I've got this Excel sheet which basically contains a lot of data.
Now, this Excel sheet is updated dynamically via a macro that imports the data. So the data might change, meaning, some cells might be populated, while others won't.

So I've got this formula in Sheet 2 in each cell from A2:A60 to M2:M60 which basically looks like this:

=IF(Sheet1!E2<>0;Sheet1!A2;"")

Meaning, if cell E2 on the row I'm in is 0, then the copied value in the new spreadsheet is nothing. Same goes for the next row:

=IF(Sheet1!E3<>0;Sheet1!A3;"")

This is repeated until row 60.

Now, what I want to do is to select the range A2:A60 and insert that data to a chart. But the thing is, the chart adds the cells that doesn't have a value. I want to exclude it from the chart without having to change the range of the chart. Is this possible using a formula in the Chart selection? Or would I have to use a macro?

Edit: Right now, the chart looks like this when I create it based on A2:A60. Notice that only A4:A17 actually have any value, the other ones have nothing, because of the formula described above.

Graph with unwanted (null) values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠栀 2024-11-25 10:30:01

您也许可以使用命名范围。

您可以定义如下名称:

Name    Definition
Date    =OFFSET(Sheet1!$A$1,1,0,COUNTA($A:$A)-1)
Value   =OFFSET(Sheet1!$B$1,1,0,COUNTA($B:$B)-1)

然后将它们用作图表中的源。

您可以找到更多信息 在 MS 网站上

[编辑] 这里还有另外两个例子:

[编辑2]聊天中的工作结果:

问题: COUNTA 公式不起作用因为单元格包含公式,所以即使为空,COUNTA 仍然对这些单元格进行计数。

解决方案:我们使用SUMPRODUCT公式来计算空值

Name   Definition
Date   =OFFSET(Sheet1!$A$2,1,0,SUMPRODUCT(IF(Sheet1!A2:A60<>"",1,0)),1))
Value  =OFFSET(Sheet1!$B$2,1,0,SUMPRODUCT(IF(Sheet1!B2:B60<>"",1,0)),1))

问候,

Max

You can probably use named range.

You can define names like :

Name    Definition
Date    =OFFSET(Sheet1!$A$1,1,0,COUNTA($A:$A)-1)
Value   =OFFSET(Sheet1!$B$1,1,0,COUNTA($B:$B)-1)

And then use them as a source in your chart.

You can find more information on MS Website.

[EDIT] Here are two other examples:

[EDIT 2] Results of the work within the chat:

Problem: the COUNTA formula did not work on the worksheet because the cells contained formulas so the COUNTA still counted these cells even if the value was empty.

Solution: we used the SUMPRODUCT formula to count the empty values

Name   Definition
Date   =OFFSET(Sheet1!$A$2,1,0,SUMPRODUCT(IF(Sheet1!A2:A60<>"",1,0)),1))
Value  =OFFSET(Sheet1!$B$2,1,0,SUMPRODUCT(IF(Sheet1!B2:B60<>"",1,0)),1))

Regards,

Max

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文