Excel VBA添加小计和删除行 [英] Excel VBA Add subtotals and remove rows

查看:395
本文介绍了Excel VBA添加小计和删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何根据不同列的值添加一个总和的行。当我这样做,我想删除添加到该值的行,并保留一行。

I am trying to figure out how I can add a row with a sum based on the values of a different column. When I do this, I'd like to remove the rows that added up to that value and retain just one row.

例如,列A有PO 10404,PO 10404,PO 10404,PO 10404,PO 10405,PO 10405.我想在PO 10404和PO 10405之间添加一行,然后将两个PO的美元金额(我猜到一个SumIf的)相加,然后删除单行,只保留一行。我需要共同的内容,如PO号码。

For instance, Column A has PO 10404, PO 10404,PO 10404,PO 10404, PO 10405, PO 10405. I'd like to add a row in between PO 10404 and PO 10405 and then sum the dollar amounts of both PO's (I'm Guessing with a SumIf's) and then delete the individual line and just keep the one line with the total. I would need the contents of the common line, like the PO number.

谢谢!
Joe

Thanks! Joe

推荐答案

您可以使用数据透视表执行此操作。使用PO#作为行标签,并将这些值用作销售金额(或任何该列所称的值)的总和。

You could do this with a Pivot Table. Use "PO#" as your row label and Sum of "Sale Amount" (or whatever that column is called) for the values.

编辑:自动化此功能的实用提示作为宏:

Helpful tips for automating this as macro:


http://www.globaliconnect.com/excel/ index.php?option = com_content& view = article& id = 147:create-an-excel-pivot-table-report-using-vba& catid = 79& Itemid = 475

然后自动保存为CSV:

Then to automate saving as a CSV:

ActiveWorkbook.SaveAs Filename:= _
"c:\MyFile.csv", FileFormat:=xlCSV _
, CreateBackup:=False

这篇关于Excel VBA添加小计和删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆