Excel - 创建具有特定标签的单元格计数

发布于 2024-11-26 22:12:48 字数 276 浏览 1 评论 0原文

我有一个包含 1000 行的数据源,其中包含以下标题:

日期|标签|我

希望能够循环遍历每一行并确定该行属于标签定义的类别。

例如

  1. 5 月 1 日 |星巴克| 10.00 美元
  2. 5 月 1 日 | 百思买 | $2.00
  3. 5 月 2 日 |好市多 | $25.00

在这种情况下,第 1 行和第 2 行3 将被归类为“咖啡”,总计 35.00 美元。

这样的宏会是什么样子?

I have a datasource with 1000 rows containing the following headers:

Date | Label | Amount

I want to be able to loop through each row and determine which category the row belongs in, as defined by the label.

E.g.

  1. 1st May | Starbucks | $10.00
  2. 1st May | BestBuy | $2.00
  3. 2nd May | CostCo | $25.00

In this scenario, row 1 & 3 would be categorised as "Coffee" leading to a total of $35.00.

What would such a macro look like?

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

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

发布评论

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

评论(2

故事和酒 2024-12-03 22:12:48

创建单独的标签和类别表后,您需要在原始表中为“类别”创建第四列。为该列中的第一条记录输入此公式:

=VLOOKUP(B2,<<label/category table address goes here, e.g. Categories!$A$1:$B$10>>,2,false)

将其填写到表格中。

现在,如果您想要按类别显示金额小计,您可以使用数据透视表轻松获得。

编辑:

如果您想要像下面的评论中所述的部分值匹配,您可以在将标签传递给 VLOOKUP 函数之前使用一些字符串操作:

=VLOOKUP(IF(MID(B2,LEN(B2)-1,1)=" ",LEFT(B2,LEN(B2)-2),B2),Categories!$A$1:$B$10,2,FALSE)

这将检查是否有空格和字母标签的末尾。如果是这样,搜索时将省略最后两个字符。否则它只会搜索标签。请注意,我在公式中有一个通用查找表地址,您需要更改该地址以匹配您的工作簿。

Once you've created your separate table of Labels and Categories, you'll need to create a fourth column for 'Category' in your original table. Enter this formula for the first record in that column:

=VLOOKUP(B2,<<label/category table address goes here, e.g. Categories!$A$1:$B$10>>,2,false)

Fill this down your table.

Now, if you want subtotals of the amount by category, you can get this easily with a pivot table.

EDIT:

If you want partial value matching like you described in the comments below, you can use some string manipulation before passing the Label to the VLOOKUP function:

=VLOOKUP(IF(MID(B2,LEN(B2)-1,1)=" ",LEFT(B2,LEN(B2)-2),B2),Categories!$A$1:$B$10,2,FALSE)

This will check to see if there's a space and letter at the end of the Label. If so, it will leave off the last two characters when searching. Otherwise it will just search for the Label. Please note that I have a generic lookup table address in the formula that you will need to change to match your workbook.

零度° 2024-12-03 22:12:48

我有一些想法可以帮助您,由于时间原因,我现在无法创建一个宏来实现我的所有想法:

  • 使用此公式添加列

    =FIND(INDIRECT(ADDRESS(initial_row_of_your_match_list + counter; _column_of_your_match_list;1));cell_where_appears_StarbucksA_StarbucksB_CostCo_etc)

在此示例中,给定 地址 给出“starbuck”的计数器,输出将为 1 或数字(部分匹配)或 #VALUE! (不匹配),实际的宏是:

* while you loop the counter throu the list
* if the result value is '1' or a number copy the corresponding value of _
  the checking_list (Starbuck) to a Results_column.

最后,您可以使用vlookupsumif单元格对行进行分类以获得最终结果。

I have some idea that can help you, by time reason I can't create right now a macro with the implementation of all my ideas:

  • add a columns with this formula

    =FIND(INDIRECT(ADDRESS(initial_row_of_your_match_list + counter; _column_of_your_match_list;1));cell_where_appears_StarbucksA_StarbucksB_CostCo_etc)

The output, in this example given a counter that address gives "starbuck", will be 1 or a number (parcial match) or #VALUE! (no match), the actual macro would be:

* while you loop the counter throu the list
* if the result value is '1' or a number copy the corresponding value of _
  the checking_list (Starbuck) to a Results_column.

finaly you can categorize you rows with vlookup and sumif the cells to obtain the final results.

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