Make range of cells equal to another range of cells in different workbooks

前端 未结 1 1061
予麋鹿
予麋鹿 2021-01-28 02:37

I would like to take a range of values from multiple workbooks and enter it into the next blank row of a master workbook. I’m trying to streamline this code as much as possible

相关标签:
1条回答
  • 2021-01-28 03:11

    Your referencing of objects is incorrect - you dont need to include the full "path" once you have set the Range objects:

    Sub CopyData()
    
    
        Dim wk1 As Workbook
        Dim wk2 As Workbook
        Dim sht1 As Worksheet
        Dim sht2 As Worksheet
        Dim Origin As Range
        Dim Destination As Range
    
        Set wk1 = Workbooks("Device")
        Set wk2 = Workbooks("Pri Access Master")
        Set sht1 = wk1.Worksheets(1)
        Set sht2 = wk2.Worksheets("Device")
        Set Destination = sht2.Range("D120000").End(xlUp).Offset(1, 0)
    
        'EDIT - dynamic copy range
        Set Origin = sht1.Range(sht1.Range("B2"), sht1.Cells(sht1.Rows.Count, "B").End(xlUp))
    
    
    
        Destination.Resize(Origin.Rows.Count, Origin.Columns.Count).Value = _
                                                               Origin.Value
    End Sub
    
    0 讨论(0)
提交回复
热议问题