我正在寻找一个宏来复制一系列单元格,但只复制包含值的单元格,并且只复制该值而不是公式。
我的问题几乎是这样的:
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
希望你们中的一些天才能够帮助我。 此致。 林戈
最佳答案
简单 - 只需稍微编辑一下 Else 语句...
' 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
Worksheets("Sheet2").cells(iRow,iCol).value = .value
End If
End With
Next iRow
Next iCol
希望这就是你的意思......
关于excel - 复制一系列单元格,仅选择包含数据的单元格,仅选择值而不是公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13351245/