简体   繁体   English

Excel宏可根据列值将行复制到新工作表

[英]Excel macro to copy rows to new sheet(s) based on column value

My query is below: 我的查询如下:

Each month my telecom provider gives me an excel list of all subscribers in the following format: 我的电信提供商每个月都会以以下格式向我提供所有订户的excel列表:

GSM number, account num, caller location, called location, units, cost

123456,     abc123456,   loc1,            loc2,            23,    11.231

123456,     abc123456,   loc8,            loc4,            5,     3

123456,     abc123456,   loc1,            loc4,            102,   71.1

789012,     def789012,   loc4,            loc5,            11,    1.43

789012,     def789012,   loc4,            loc5,            1,     0.23

345678,     ghi345678,   loc6,            loc7,            7,     2.23

and so on.. 等等..

I'd want to go through the column A (gsm number) and copy all rows for that number to a worksheet named for the number, eg rows 1-3 would be copied to a worksheet named 123456. 我想遍历A列(gsm编号)并将该编号的所有行复制到以该编号命名的工作表中,例如,第1-3行将复制到名为123456的工作表中。

I've managed to go though some other queries on this site and come up with something that works, but doesn't. 我设法浏览了该网站上的其他一些查询 ,并提出了一些可行的方法,但没有成功。 The problems I'm facing is that the number of rows for a particular caller are not fixed (one row per call) and the number of callers are not fixed either (zero calls means no rows). 我面临的问题是特定呼叫者的行数不固定(每个呼叫一行),呼叫者的数目也不固定(零呼叫意味着没有行)。 I'm trying for a OnCellValueChange type solution - since I can understand & edit macros - but haven't written one yet. 我正在尝试一种OnCellValueChange类型的解决方案-因为我可以理解和编辑宏-但是还没有编写。

Thanks for your time! 谢谢你的时间!

edit: also, as a side-note, can I also put a total of the "cost" column on each spreadsheet? 编辑:此外,作为补充说明,我是否还可以在每个电子表格中总共添加“费用”列?

Edit Edit: Thanks to all for your solutions. 编辑编辑:感谢您的解决方案。 However, my uncomfortability with VBA was hampering me. 但是,我对VBA的不舒服妨碍了我。 So, I'm just taking the excel sheet as-is in an SQL database and doing all of the formatting and querying in SQL/ASP directly online. 因此,我只是将Excel工作表直接保存在SQL数据库中,并直接在线进行SQL / ASP中的所有格式和查询。 So now users simply enter their phone # (and a password) and see their call records with dynamically generated subtotals and sortings. 因此,现在用户只需输入他们的电话号码(和密码),即可查看他们的通话记录以及动态生成的小计和排序。 Thanks y'all for your very kind help. 谢谢大家的帮助。

As @joseph4tw says, you could do this with a pivot table similar to below (Excel 2010)... 正如@ joseph4tw所说,您可以使用类似于下面的数据透视表来做到这一点(Excel 2010)...

  • To show all item labels, choose: Field Settings -> Layout & Print -> Repeat Item Labels 要显示所有项目标签,请选择: 字段设置->布局和打印->重复项目标签

  • To create the sheet tabs just select Pivot Table Options -> Show Report Filter Pages (as below) 要创建工作表标签,只需选择数据透视表选项->显示报告过滤器页面 (如下所示)

在此处输入图片说明

在此处输入图片说明

Update Having created the sheet tabs, you can use group editing to format as required... 更新创建工作表标签后,您可以根据需要使用组编辑进行格式化...

  • select all the tabs by shift-clicking the last tab, 按住Shift键并单击最后一个标签,选择所有标签,
  • select the whole sheet and paste special values to remove all pivot tables 选择整个工作表并粘贴特殊值以删除所有数据透视表
  • delete the first two rows and autosize columns as shown 删除前两行并自动调整列大小,如图所示

在此处输入图片说明

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

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