我正在研究一个宏,它可以帮助我在一些条件下将数据从一个工作表复制到另一个工作表。问题是有些行包含公式,而我需要值。
答案 0 :(得分:2)
只需使用.copy
和.PasteSpecial xlPasteValues
,然后它就会粘贴值。
exsample:
Thisworkbook.sheets("Sheet1").Range("A1").copy
Thisworkbook.sheets("Sheet2").Range("A1").PasteSpecial xlPasteValues
答案 1 :(得分:0)
试试这个,它会复制并删除公式,保留值:
Sub copier()
Dim ws1 As Worksheet, ws2 As Worksheet, src As Range, dest As Range, i As Integer
Set ws1 = Worksheets("Workload - Charge de travail")
Set ws2 = Worksheets("Sheet1")
For i = 2 To ws1.UsedRange.Rows.Count
Set src = ws1.Range("A" & i & ":AG" & i)
Set dest = ws2.Range("A" & i & ":AG" & i)
' ... you can add some checking here to check if the condition is met on the src range...
src.Copy Destination:=dest
dest.Value = dest.Value
Next i
End Sub