从第二张到第三张使用excel

从第二张到第三张使用excel

本文介绍了将数据从一张纸复制并粘贴到另一张纸,从第二张到第三张使用excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有要求,我需要将范围的单元格单元格中的值(而不是公式)复制到另一个表格中的相应单元格,然后从第二页的第二页复制到相应的单元格。

I have requirement, where I need to copy values(not formula) in a sheet cells part of a range to corresponding cells in another sheet and then from second sheet to corresponding cells in third sheet.

从前两秒复制数据我正在使用以下代码,

for copying data from first two second I am using below code,

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不同。

Now, I would like to copy from sheet2 to sheet3. I need this specifically from sheet2, because my first sheet may have different value than sheet2.

推荐答案

如果您需要Sheet1包含公式,但是您需要Sheet2和Sheet3仅包含值,请将您的代码修改为以下内容:

If you need Sheet1 to contain the formulas, but you need Sheet2 and Sheet3 to contain just the values, modify your code to the following:

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

这篇关于将数据从一张纸复制并粘贴到另一张纸,从第二张到第三张使用excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:38