-1

'我的代码是从打开的工作簿中的每个工作表中复制数据并粘贴到其主数据表中。

Sub CallData()
            
        Dim CorpFile As Worksheet, CopyRg As Range, PasteRg As Range
        
        Set CorpFile = Sheets("MasterData")
        Set CopyRg = ActiveSheet.UsedRange
        Set PasteRg = CorpFile.Cells(Rows.Count, 1).End(xlUp).Row + 1 'it is stuck here
        
        For Each Sheet In ThisWorkbook
        
        If ActiveSheet.Name <> CorpFile Then
        
        CopyRg.Copy PasteRg
        
        End If
        
        Next Sheet
        
        End Sub
4

1 回答 1

2
Option Explicit
Sub CallData()

    Dim CorpFile As Worksheet, sheet As Worksheet
    Dim PasteRg As Range
        
    Set CorpFile = ThisWorkbook.Sheets("MasterData")
    
    For Each sheet In ThisWorkbook.Sheets
    
        If sheet.Name <> CorpFile.Name Then

            Set PasteRg = CorpFile.Cells(Rows.Count, 1).End(xlUp).Offset(1)
            sheet.UsedRange.Copy PasteRg
            
        End If
    
    Next sheet
        
End Sub
于 2021-05-09T12:25:03.247 回答