2016-11-30 145 views
0

我試圖從名爲「everett」的名爲「DDR」&選項卡的文件中使用XLDOWN從單元格「A9」中複製所有結果並將其粘貼回來到當前正在使用的工作簿中。將外部工作簿XLDOWN複製到當前工作簿

任何幫助,將不勝感激

Sub XLDOWN1() 
' 
' XLDOWN1 Macro 
' 

' 
    Dim wbSource As Workbook, wbDest As Workbook 
    Dim wsSource As Worksheet, wsDest As Worksheet 
    Dim rngSource As Range, rngDest As Range 

    Set wbSource = Workbooks.Open("G:\GAGC\Accounting\Payroll\Payroll\Analysis Macro Upload\DDR.xlsx", , True) 
    Set wsSource = wbSource.Worksheets("Everett") 


    ws.Range("A9", Range("A9").End(xlDown)).Select 
    Selection.Copy 



    Set rngSource = wsSource.Range("A9").Range(Selection, Selection.End(xlDown)) 
    Set wbDest = ThisWorkbook 
    Set wsDest = wbDest.Worksheets("2016") 
    Set rngDest = wsDest.Range("A4") 'Destination Cell 

    rngDest.Value = rngSource.Value 'Copies values over only 

    wbSource.Close (False) 'Close without saving changes 


End Sub 

回答

0

給這個一杆。您提供的代碼中有幾個問題應該在查看下面重構的代碼後清楚。

Dim wbSource As Workbook, wbDest As Workbook 
Dim wsSource As Worksheet, wsDest As Worksheet 
Dim rngSource As Range, rngDest As Range 

'set up source workbook, sheet, range 
Set wbSource = Workbooks.Open("G:\GAGC\Accounting\Payroll\Payroll\Analysis Macro Upload\DDR.xlsx", , True) 
Set wsSource = wbSource.Worksheets("Everett") 
Set rngSource = wsSource.Range(wsSource.Range("A9"), wsSource.Range("A9").End(xlDown)) 

'set up destination workbook, sheet, range 
Set wbDest = ThisWorkbook 
Set wsDest = wbDest.Worksheets("2016") 
Set rngDest = wsDest.Range("A4") 'Destination Cell 

rngSource.Copy Destination:=rngDest 

wbSource.Close False 
相關問題