我發現這個宏,它做我需要它做但是每當它被激活它似乎複製/粘貼數據多次。我的主列表應該只有75行左右,當它運行時,它最終會在268.爲什麼這樣做?另外,是否有編輯它的方法,如果在「A1」之後表格中沒有數據,它不會複製該表格?這個宏爲什麼複製多次?
Option Explicit
Private Sub Worksheet_Activate()
'Merge all sheets in a workbook into one summary sheet (stacked)
Dim cs As Worksheet, ws As Worksheet, LR As Long, NR As Long
Application.ScreenUpdating = False
Set cs = Sheets("Master List")
cs.Activate
Range("A2:F" & Rows.Count).ClearContents
For Each ws In Worksheets
If ws.Name <> "Master List" Then
NR = cs.Range("A" & Rows.Count).End(xlUp).Row + 1
LR = ws.Range("A" & Rows.Count).End(xlUp).Row
ws.Range("A2:F" & LR).copy cs.Range("A" & NR)
End If
Next ws
Application.ScreenUpdating = True
End Sub
要跳過一個WS,在單元格A1中沒有數據,將條件更改爲:如果ws.Name <>「Master List」和isempty(ws.Range(「A1」))= False Then' – DyRuss