调整macrosvba模块来粘贴值只有不公式

我把一个macros放在一个表中search一个表,并且只将该表中具有数值的那一行复制粘贴到电子表格的下一个表格上。 一旦按下button,就会发生这种情况。 我的代码如下:

Sub Button1_Click() Dim r As Long, endRow As Long, pasteRowIndex As Long Set WS = Worksheets("Sheet1") With WS Set LastCell = .Cells(.Rows.Count, "C").End(xlUp) LastCellRowNumber = LastCell.Row End With 'endRow = 20 of course it's best to retrieve the last used row number via a function pasteRowIndex = 1 For r = 2 To LastCellRowNumber 'Loop through sheet1 and search for your criteria If IsNumeric(Cells(r, Columns("E").Column).Value) And Not IsEmpty(Cells(r, Columns("E").Column).Value) Then 'Found 'Copy the current row Rows(r).Select Selection.Copy 'Switch to the sheet where you want to paste it & paste Sheets("Sheet2").Select Rows(pasteRowIndex).Select ActiveSheet.Paste 'Next time you find a match, it will be pasted in a new row pasteRowIndex = pasteRowIndex + 1 'Switch back to your table & continue to search for your criteria Sheets("Sheet1").Select End If Next r End Sub 

这工作,但我的问题是,它复制与他们的公式的行(一旦复制变得不可用),所以我需要某种粘贴专门只复制的值。 我试过这个,但要么继续得到错误,要么不以同样的方式工作..有人可以检查我,并指出我在正确的方向吗?

 Sub Button1_Click() Dim r As Long, endRow As Long, pasteRowIndex As Long, Location As Long Set WS = Worksheets("Sheet1") With WS Set LastCell = .Cells(.Rows.Count, "C").End(xlUp) LastCellRowNumber = LastCell.Row End With pasteRowIndex = 1 For r = 2 To LastCellRowNumber 'Loop through sheet1 and search for your criteria If IsNumeric(Cells(r, Columns("E").Column).Value) And Not IsEmpty(Cells(r, Columns("E").Column).Value) Then 'Found Location = 1 'Copy the current row Rows(r).Select Selection.Copy 'Switch to the sheet where you want to paste it & paste Sheets("Sheet2").Select Rows(pasteRowIndex).Select ActiveSheet.Range(Cells(Location, 1)).PasteSpecial xlPasteValues Application.CutCopyMode = False 'Next time you find a match, it will be pasted in a new row pasteRowIndex = pasteRowIndex + 1 Location = Location + 1 'Switch back to your table & continue to search for your criteria Sheets("Sheet1").Select End If Next r End Sub 

非常感谢!

 ActiveSheet.Range(Cells(Location, 1)).PasteSpecial xlPasteValues 

您不能在范围内单独嵌套单元格 – 单元格已经是范围:

 ActiveSheet.Cells(Location, 1).PasteSpecial xlPasteValues