单元格中的VBA Excel行中断

我一直在寻找解决这个问题一个多星期。 我有一张带有格式化文本(颜色和样式)的表格,其值与第一列的距离不确定。 中间有一些空格,但我相信我已经通过使用IsEmpty正确处理了这种情况。 我想将每个单元格中的每个值都复制到第二列顶部的一个单元格中。 我已经成功地将每个单元格的文本复制到指定的连续单元格中,但是我在保持格式化方面没有成功。 任何人都可以提供有关如何复制格式与此文本的帮助将不胜感激。 谢谢!

'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 

你可以使用Range.Copy和Range.PasteSpecial属性,它很容易使用,并且解决了格式化单元格的问题。