【发布时间】:2013-11-27 20:43:06
【问题描述】:
我想遍历存储在不同单元格中的数据(类似于下面显示的数据),并将它们组合成一个由新行分隔的单个单元格 (chr(10))。 需要导入一个单元格的数据量会发生变化。
2991
19391
423
435
436
代码需要遍历整个工作表,而不考虑任何换行符。要求的格式是:
2991 - all three cells would be combined into one cell in the next column to this one.
19391
423
-Line space, this will need to be taken into account and is the seperator of data.
26991 - all four cells would be combined into one cell in the next column to this one.
19331
424
6764
下面是我目前得到的,它把当前行左边的列合并起来,这是错误的。
Sub ConcatColumns()
Do While ActiveCell <> "" 'Loops until the active cell is blank.
ActiveCell.Offset(0, 1).FormulaR1C1 = _
ActiveCell.Offset(0, -1) & chr(10) & ActiveCell.Offset(0, 0)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
【问题讨论】:
标签: vba excel excel-2007