使用VBA将所有格式从一张纸复制到另一张纸

时间:2019-07-05 04:38:14

标签: excel vba

我正在使用以下代码将值从一张纸复制到另一张纸上

Lastrow = WAEnv.Cells(Rows.Count, 1).End(xlUp).Row
Xrow = 1

lcol = Cells(3, Columns.Count).End(xlToLeft).Column
vArr = Split(Cells(1, lcol).Address(True, False), "$")

Debug.Print Xrow
For Rw = 3 To Lastrow
    Set Rng = WAEnv.Range("A" & Rw & ":" & vArr(0) & Rw)

    If Rng(1, 1).Value > 0 Then
        ReDim Preserve DstArr(1 To lcol, 1 To Xrow)
        Xcol = 1

        For Each cl In Rng.Columns.Cells
            DstArr(Xcol, Xrow) = cl.Value
            Xcol = Xcol + 1
        Next cl

        WAPatch.Cells(Xrow, 1).RowHeight = Rng(1, 1).RowHeight
        Xrow = Xrow + 1
    End If
Next Rw

WAPatch.Range("A3").Resize(UBound(DstArr, 2), UBound(DstArr, 1)).Formula = Application.Transpose(DstArr)

我已经知道我可以使用cpy进行所有格式化,但是下面的代码非常慢,因此我正在使用上面提到的数组方法。

WAEnv.Cells(i, j).Copy
WAPatch.Cells(ro, j).PasteSpecial Paste:=xlPasteAll

我在寻找什么,可以使用我一直使用的数组方法将所有格式从一张纸粘贴粘贴到另一张纸?

0 个答案:

没有答案