想要在我的excel VBA编码中添加另外两个条件

时间:2019-04-11 18:03:29

标签: excel vba

我要添加的是..宏应从“主”表中删除旧文件,并刷新sheet1,sheet2和sheet3

Sub Combine3Sheet()

Dim Ary As Variant
Dim Ws As Worksheet

Ary = Array("Sheet1", “Sheet2", "Sheet3")
Sheets("Master").Name = "Master"

For Each Ws In Worksheets(Ary)
    Ws.UsedRange.Offset(1).Copy Sheets("Master") _
    .Range("A" & Rows.Count).End(xlUp).Offset(1)

    Application.DisplayAlerts = False
    Application.DisplayAlerts = True

    Call Formatting

Next Ws

结束子

1 个答案:

答案 0 :(得分:1)

这是您的意思吗?在粘贴之前要删除母版上的数据吗?

(也停止更改帖子的编辑内容)

Sub Combine3Sheet()
    Dim Ary As Variant
    Dim Ws As Worksheet
    Ary = Array("Sheet1", "Sheet2", "Sheet3")
    'Refresh all sources/Tables
    ThisWorkbook.RefreshAll
    'Clear All but first Row
    Sheets("Master").Rows("2:" & Rows.Count).ClearContents
    'Loop sheets
    For Each Ws In Worksheets(Ary)
        Ws.UsedRange.Offset(1).Copy
        Sheets("Master").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
        Call Formatting
    Next Ws
End Sub