如何使用宏将数据从行转置为列
我对 VBA 完全陌生(除了手动录制和运行),所以希望有人可以帮助我设计这个。我有一个工作表,根据日期和类型,每个唯一 ID(A 列)的行数未指定。 :
A B C D
1 12Jan2010 type A Person1
1 16Jan2010 type B Person1
2 06Dec2009 type A Person2
3 16Dec2009 type A Person1
5 20Dec2009 type A Person2
5 02Jan2010 type B Person2
4 10Dec2009 type A Person2
基于唯一 ID,我想将此数据转置为每个唯一 ID 的 1 行,然后将所有日期值按时间顺序排列在该行中,如下所示:
A B C D
1 Person1 12Jan2010(A) 16Jan2010(B)
2 Person2 06Dec2009(A)
3 Person1 16Dec2009(A)
4 Person2 10Dec2009(A)
5 Person2 20Dec2009(A) 02Jan2010(B)
有没有办法可以完成此操作在宏中?
I am totally new to VBA (aside from recording and running manually) so was hoping somebody could help me with designing this. I have a worksheet with unspecified # of rows per unique ID (column A), based on date and type. :
A B C D
1 12Jan2010 type A Person1
1 16Jan2010 type B Person1
2 06Dec2009 type A Person2
3 16Dec2009 type A Person1
5 20Dec2009 type A Person2
5 02Jan2010 type B Person2
4 10Dec2009 type A Person2
based on the unique ID, I would like to transpose this data into 1 row per unique ID, and then have all the date values put in chronological order across the row so it looks like this:
A B C D
1 Person1 12Jan2010(A) 16Jan2010(B)
2 Person2 06Dec2009(A)
3 Person1 16Dec2009(A)
4 Person2 10Dec2009(A)
5 Person2 20Dec2009(A) 02Jan2010(B)
Is there a way I can have this done in a macro?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用数据透视表!选择整个表,并创建一个数据透视表,其中侧字段为 A 列,顶部字段为 B 列,并且仅在中间聚合部分中对 A 列进行计数。
您最终会得到一个由唯一 id 作为行、日期作为列以及交叉点处的行数组成的矩阵!
Use a Pivot Table! Select the whole table, and create a pivot table with the side field being column A, the top field being column B and just do count of column A in the middle aggregate section.
You'll end up with a matrix of unique id's as rows, dates as columns, and counts of rows at intersections!