Excel根据相邻值生成文本
我想知道是否有可能根据这个表格的相邻值生成文本:
Column A Column B(Count) Text 1 3 Text 2 5
最终的结果应该是脚本运行的时候:
Column A Text 1 Text 1 Text 1 Text 2 Text 2 Text 2 Text 2 Text 2
在Google上search这个,我找不到我要找的结果。 我认为VBAmacros将做的伎俩? 对于循环将是我的猜测。 把这看作是反转数据透视表的过程来find唯一的值。
有了A和B列的数据,这个小macros:
Sub Repetition() Dim N As Long, i As Long, K As Long N = Cells(Rows.Count, "A").End(xlUp).Row K = 1 For i = 1 To N For j = 1 To Cells(i, 2).Value Cells(K, 3).Value = Cells(i, 1).Value K = K + 1 Next j Next i End Sub
会产生:
你不需要这个VBA。 你可以在相邻的单元格中添加一个公式:
=(A1 & " " & B1)
除非你真的想使用VBA。 在这种情况下,这个答案不适用。