[英]VBA - Find all values on column B for article on column A and place them to a single row
I have a very large Excel document (20k entries) with data similar to this: 我有一个非常大的Excel文档(2万个条目),其数据类似于以下内容:
ARTICLE TIME
article 1 1s
article 1 2s
article 2 1s
article 2 2s
article 2 3s
...
I need to extract the unique values from the articles column and place their corresponding time values on a single row, like this: 我需要从articles列中提取唯一值,并将其对应的时间值放在一行中,如下所示:
ARTICLE TIMES
article 1 1s 2s
article 2 1s 2s 3s
...
I tried with formulas (INDEX, MATCH, FIND etc...) but I didn't get any proper results. 我尝试使用公式(INDEX,MATCH,FIND等...),但没有得到任何正确的结果。
How can I do this using VBA (maybe?) Thanks. 我如何使用VBA做到这一点(也许?)谢谢。
Try the following code in Before Click event: 在“单击之前”事件中尝试以下代码:
cnt = 8
For i = 2 To 6
strg = strg & Cells(i, 2)
If Cells(i, 1) <> Cells(i + 1, 1) Then
Cells(cnt, 1) = Cells(i, 1)
Cells(cnt, 2) = strg
strg = ""
cnt = cnt + 1
End If
Next
The time values are populated in a single cell against each Article 时间值在每个文章的单个单元格中填充
Here is a recipe without using VBA 这是不使用VBA的食谱
build aggregated TIMES for each article 为每篇文章建立汇总时间
ARTICLE TIME SAME TIMES article 1 1s =if(A3=A2;"YES";"") =B2 article 1 2s =if(A3=A2;"YES";"") = if(A3=A2;Concatenate(B3;" ";D2);B3) article 1 3s =if(A4=A3;"YES";"") = if(A4=A3;Concatenate(B4;" ";D3);B4) article 2 1s (extend the formulas down to the end of range)
Create a copy, replacing the formulas in SAME and TIMES by the result select columns C and D menu -> copy select columns C and D agin menu -> paste special ; 创建一个副本,将CAME和TIMES中的公式替换为结果选择列C和D菜单->复制选择列C和D再次菜单->粘贴特殊; values only
仅值
Sort the list by "SAME" (this will put all "YES" in a single block) 按“相同”对列表进行排序(这会将所有“是”放在一个块中)
Remove all SAME="YES" columns 删除所有SAME =“ YES”列
Sort back to ascending list of articles 排序回升序的文章列表
Remove "TIME" and "YES" columns 删除“时间”和“是”列
Done. 完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.