VBA Excel-复制和粘贴列宽/分组

时间:2018-08-29 21:59:01

标签: excel vba excel-vba loops copy-paste

我正在尝试将整个工作表从“ DNU”复制到每个后续工作表中。我希望进行常规粘贴以保留宽度和分组,但这只会粘贴公式和表格格式。谢谢。

代码如下:

Dim wsVar As Worksheet
Dim i as Integer
With ThisWorkbook
    For i = 6 to .Worksheets.Count
        .Worksheets("DNU").Range("A1:Y200").Copy destination:=.Worksheets(i).Range("A1:Y200")
    Next 
End With

1 个答案:

答案 0 :(得分:0)

您不需要使用copy/pasteValue可以让arguments11传递值和格式。

Dim i As Integer
With ThisWorkbook
    For i = 2 To .Worksheets.Count
        .Worksheets(i).Range("A1:Y200").Value(11) = .Worksheets("Sheet1").Range("A1:Y200").Value(11)
        'Unsure how you accomplish your grouping,
        .Worksheets(i).Range("A1:Y200").OutlineLevel = .Worksheets("Sheet1").Range("A1:Y200").OutlineLevel

        Dim colx As Long
        For colx = 1 To 25
            Worksheets(i).Columns(colx).ColumnWidth = Worksheets("Sheet1").Columns(colx).ColumnWidth
            Worksheets(i).Columns(colx).OutlineLevel = Worksheets("Sheet1").Columns(colx).OutlineLevel
        Next

        Dim rowx As Long
        For rowx = 1 To 200
            Worksheets(i).Rows(rowx).OutlineLevel = Worksheets("Sheet1").Rows(rowx).OutlineLevel
        Next

    Next
End With