我有要求,我需要将范围的单元格部分中的值(非公式)复制到另一个工作表中的相应单元格,然后从第二个工作表复制到第三个工作表中的相应单元格。
从前两秒复制数据我使用下面的代码,
Sub Test()
Dim rng As Range
Dim c As Range
Dim dest As Worksheet
Set rng = Range("C3:E3")
Set dest = ThisWorkbook.Worksheets("Sheet2")
For Each c In rng
c.Copy dest.Cells(c.Row, c.Column)
Next c
End Sub
现在,我想从sheet2
复制到sheet3
。我需要专门从sheet2
开始,因为我的第一张纸可能与sheet2的价值不同。
答案 0 :(得分:1)
如果您需要Sheet1来包含公式,但需要Sheet2和Sheet3仅包含值,请将代码修改为以下内容:
Sub Test()
Dim rng As Range
Dim c As Range
Dim dest As Worksheet
Dim dest2 As Worksheet
Set rng = Range("C3:E3")
Set dest = ThisWorkbook.Worksheets("Sheet2")
Set dest2 = ThisWorkbook.Worksheets("Sheet3")
For Each c In rng
c.Copy
dest.Cells(c.Row, c.Column).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
dest2.Cells(c.Row, c.Column).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next c
Application.CutCopyMode = False
End Sub