【发布时间】:2016-04-22 04:36:35
【问题描述】:
*编辑添加:我收到的当前错误。截图见本帖底部。
我在 D 列中有文本。宏应该找到空白单元格,然后将其下方所有单元格中的文本连接起来。
示例
从 D2 开始的文本,显示如下...
Blank Cell
SampleText1
SampleText2
SampleText3
Blank Cell
SampleText4
SampleText5
SampleText6
宏应该在 D2 中显示文本...
SampleText1, SampleText2, SampleText3
然后在 D6 中,像这样......
SampleText4, SampleText5, SampleText6
..等等。
这只需要在 D 列中起作用,所以我猜我可以将它写入该范围。
我遇到的最接近的答案在这里: Excel Macro to concatenate
这是我目前正在使用的代码...
Sub ConcatColumns()
Do While ActiveCell <> "" 'Loops until the active cell is blank.
'The "&" must have a space on both sides or it will be
'treated as a variable type of long integer.
ActiveCell.Offset(0, 1).FormulaR1C1 = _
ActiveCell.Offset(0, -1) & " " & ActiveCell.Offset(0, 0)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
编辑:现在使用来自@jeeped 的优秀代码,但收到错误,如下图所示
【问题讨论】:
标签: vba excel concatenation