简体   繁体   English

VBA-在B列中找到A列上的商品的所有值,并将它们放在一行中

[英]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的食谱

  1. 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) 
  2. 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 仅值

  3. Sort the list by "SAME" (this will put all "YES" in a single block) 按“相同”对列表进行排序(这会将所有“是”放在一个块中)

  4. Remove all SAME="YES" columns 删除所有SAME =“ YES”列

  5. Sort back to ascending list of articles 排序回升序的文章列表

  6. Remove "TIME" and "YES" columns 删除“时间”和“是”列

Done. 完成。

暂无
暂无

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

相关问题 将单个单元格中的B列行值与A列连接 - Concatenate column B row values in single cell against column A 通过 VBA 减去:C 列中的行值 = A 列中的行值 - B 列中的行值 - Subtract via VBA: Rows values in Column C = Row values in Column A - Row values in Column B 循环 A 列中的所有值以查找 B 列中的所有匹配项 - Loop all values in column A to find all matches in column B vba 在 B 列中找到最后一行并调整表格范围 - vba find last row in column B and resize table range VBA - 在具有条件的列中查找所有相同的值 - VBA - Find all same values in a column with a condition Excel VBA在行中查找所有值并将不同的列值保存到变量 - Excel VBA find all values in row and save different column values to variables Excel VBA —查找列A中任何值的第一个出现位置,然后将列B的值插入列C(同一行) - Excel VBA — Find first occurrence of any value in column A, then insert value of column B into column C (same row) VBA在A列中找到x值,在B列中找到y值,在C列中找到和值 - VBA find value x in column A and value y in column B and sum values in column C Excel VBA脚本来计算A列中小于同一行的B列中的值的数量 - Excel VBA script to count the number of values in column A that are less than the values in Column B same row 如何将列B的所有行粘贴到Excel VBA中的列A的第n行 - How to paste from column B all rows to column A's nth row in Excel VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM