我一直在寻找这个问题的解决方案一个多星期了。我有一张带格式文本(颜色和样式)的表格,其值与第一列的距离不确定。中间有一些空格,但我相信我已经通过使用IsEmpty正确处理了这种情况。我想将每个单元格中的每个值都复制到第二列顶部的一个单元格中。我已经成功地将每个单元格中的文本复制到指定的带连续符的连接单元格中,但是我一直未能保持格式化。任何人都可以提供关于如何复制格式与本文一起帮助将不胜感激。谢谢!VBA Excel行中的单元格中断
'set variable to find the last row of the sheet
Dim LastRow As Integer
'find the last row of the active sheet
LastRow = ActiveSheet.UsedRange.Rows.Count
'loop through each of the rows
For C = 1 To LastRow
'determine if a cell has a value in it - if so complete below commands
If (IsEmpty(Cells(C, 1).Value) = False) Then
'leave the contents of the first cell in the second column, insert a linebreak and copy the values from the current cell in the first column
Cells(1, 2).Value = Cells(1, 2).Value & Chr(10) & Cells(C, 1).Value
End If
Next C
请参阅此主题http://www.mrexcel.com/forum/showpost.php?p=3034158&postcount=5安德鲁Poulsom已经给出了你想要的代码。 – 2012-04-17 18:24:27
请注意,该代码中存在一个错误:如果要连接的第一个值具有任何前导空格,则在并置循环后调用'Trim()'会将所有以下格式化步骤的前导空格数修剪掉... – 2012-04-17 18:50:35
感谢您的链接,这完成了我正在寻找和更多 – 2012-04-17 18:59:38