简体   繁体   English

将列的子集转置为行,并将其余的列保留在Excel VBA中

[英]Transpose a subset of columns into rows and keep remaining columns in Excel VBA

I have data for an event registration that will be coming to me weekly in CSV a file. 我有活动注册的数据,每周将以CSV文件的形式发送给我。 I have dummied down the data for simplicity, but the basic idea is that it will look like the following: 为了简化起见,我对数据进行了删减,但是基本思想是它看起来如下所示:

Team Name1 Name2 Name3 Total
1    a     b     c     10
2    d     e     f     20
3    g     h     i     30
4    j     k     l     40
5    m     n     o     50
6    p     q     r     60
7    s     t     u     70

Each week for the full data set I need to be able to transpose columns Name1, Name2, and Name 3 into rows and keep all other columns the same so that it looks like the following: 每周,我需要能够将完整的数据集转换为行Name1,Name2和Name 3到行中,并使所有其他列保持相同,以便其外观如下所示:

Team Name Total
1    a    10
1    b    10
1    c    10
2    d    20
2    e    20
2    f    20
3    g    30
3    h    30
3    i    30
4    j    40
4    k    40
4    l    40
5    m    50
5    n    50
5    o    50
6    p    60
6    q    60
6    r    60
7    s    70
7    t    70
7    u    70
  • The final format needs to be in an Excel file. 最终格式必须在Excel文件中。
  • What is the best approach for this sort of task? 进行此类任务的最佳方法是什么? Excel/VBA? Excel / VBA? Access? 访问?
  • I don't have to have the column names in the final format (I could just add those back in myself if that adds too much to the complexity). 我不必使用最终格式的列名(如果这样会增加复杂性,我可以将它们自己添加回去)。

I tried this with VBA using what I could find on the internet as I am not a VBA expert, so before I went further trying to learn VBA more thoroughly, I thought I would see what technology is most recommended and whether or not anyone has a simple solution that might work. 我不是VBA专家,而是使用Internet上的VBA进行了尝试,因此在进一步尝试更深入地学习VBA之前,我想我会发现最推荐使用哪种技术以及是否有人拥有可能有效的简单解决方案。

Thank you for your help. 谢谢您的帮助。

My first thought was Access, but if this is all you're doing, you can stay in Excel. 我的第一个想法是Access,但是如果您要做的只是此操作,则可以继续使用Excel。

This can even be done without VBA--just Excel formulas using MATCH() (for the team name, returns the Excel row) and INDEX() (give it the MATCH() result and it will return NAME1, 2 or 3 or Total). 甚至可以在没有VBA的情况下完成-只需使用MATCH()(对于团队名称,返回Excel行)和INDEX()(将其MATCH()结果作为Excel公式),它将返回NAME1、2或3或Total )。

[SOLVED] A friend just helped me write an awk script to create a new CSV file instead, and it was pretty simple. [已解决]一位朋友只是帮我写了一个awk脚本来创建一个新的CSV文件,这非常简单。 I am going to go that route. 我要走那条路。

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

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