【问题标题】:Copy a value in one cell, based on other cell and structure the data根据其他单元格复制一个单元格中的值并构建数据
【发布时间】:2012-08-03 09:10:02
【问题描述】:

我有一个数据表,其中包含人员的姓名和他们每天工作的小时数。我需要总结每个人每天和每周工作的数字。 工作表是这样的

  A      B  
Peter  8.000  
Bob    4.000  
Jane   3.000  
Jane   4.000  

每个人都有几个条目,我的老板希望我每周和每月显示它们,这样他就可以跟踪某人最近是否比其他人加班。

【问题讨论】:

  • 你怎么知道哪一天的工作时间?
  • 不确定是否需要宏?
  • 尝试寻找SUMIF公式
  • 这不是数据透视表的用途吗?

标签: excel vba


【解决方案1】:

我同意 Jmax 和 KingCronus 的观点。您实际上不需要宏。你可以用一个公式来实现它。

非 VBA

我假设值在 Col A 和 Col B 中。

=SUMPRODUCT((A:A="Jane")*(B:B))

VBA

如果你仍然想要 VBA,那么你可以使用它

Sub Sample()
    Dim sName As String

    sName = "Jane"

    Debug.Print Application.Evaluate("=SUMPRODUCT((A:A=" & _
    Chr(34) & sName & Chr(34) & ")*(B:B))")
End Sub

【讨论】:

  • 大家好。感谢您的提示,但t work. I am not sure if that makes any difference, but i changed the columns, because those one in the example were fictional. Indeed the sheet is wider than this and it has several columns, like responsible manager and etc, but i dont 认为这些很重要。我通过 excel 评估了公式,每一步都给了我 FALSE,我还尝试更改数值的格式,但效果不佳。我的 excel 版本是 2010,但我不确定这是否与它有关。
  • 我实际上使用了数据透视表,所以现在我有了我需要的东西。谢谢大家。
  • 我已经测试了上面的公式和代码,它按预期工作。如果您可以向我展示一个确切的样本,那么我们可以了解它为什么不适合您。但是,如果您想坚持使用数据透视表,那么这也是一个好主意。
  • 我不知道可以使用语法A:A="Jane" 过滤范围。还有什么我不知道的?你知道我在哪里可以找到文档吗?
猜你喜欢
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多