复制一个单元格的范围,只select单元格与数据,只是值不是公式

我正在寻找一个macros来复制一个单元格的范围,但只复制包含一个值的单元格,而不是公式的值。

我的问题几乎是这样的:

复制一个单元格范围,只select数据单元格

我发现这个macrosbrilljant :)但它只是缺less我需要:(

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 

希望这是你的意思….

要将所有单元格从Sheet1列的使用部分A:C复制到Sheet2,作为可以使用的值

无论如何复制空白单元格将是空白的。

 Sub Better() Dim ws As Worksheet Set ws = Sheets("Sheet1") Set rng1 = ws.Range(ws.[a1], ws.Cells(Rows.Count, "A").End(xlUp)) Sheets("Sheet2").Range(rng1.Address).Value = rng1.Value End Sub