【发布时间】:2012-11-12 20:42:08
【问题描述】:
我正在寻找一个宏来复制一系列单元格,但只复制包含值的单元格并且只复制值而不是公式。
我的问题差不多是这样的:
Copy a range of cells and only select cells with data
我找到了这个宏 :) 但它只是缺少我需要的东西:(
iMaxRow = 5000 ' 或任何最大值。 '不要太大,因为这会减慢你的代码。
' Loop through columns and rows
For iCol = 1 To 3 ' or however many columns you have
For iRow = 1 To iMaxRow
With Worksheets("Sheet1").Cells(iRow,iCol)
' Check that cell is not empty.
If .Value = "" Then
'Nothing in this cell.
'Do nothing.
Else
' Copy the cell to the destination
.Copy Destination:=Worksheets("Sheet2").cells(iRow,iCol)
End If
End With
Next iRow
Next iCol
我希望你们中的一些天才可以帮助我。 此致。 林哥
【问题讨论】:
-
你为什么不一次复制所有单元格并粘贴特殊值 - 无论如何空白都会复制为空白?循环显得多余。