Home > Software engineering >  Vba merge more than a folder excel table data
Vba merge more than a folder excel table data

Time:11-09

There are two files, named A and B


Purpose: to use VBA code to A, B two folder file merging summary to an excel workbook. A, B the working table



Here is to compile A file folder code written
 Sub aggregate (A) 

Dim myfile mypath, wb 'declare variables
Application. ScreenUpdating=False 'close the screen update
Sheet1. UsedRange. Offset (1, 0). The Clear 'remove everything except header
Mypath=the path of the "A" 'find the path of the current workbook "
Myfile=Dir (mypath & amp; "\ *. * XLSX") 'traversal Excel file under the current folder
The Do While myfile & lt;> "" 'when find file is not empty
If myfile & lt;> ThisWorkbook. Name Then 'when find file is not currently Excel workbook
The Set wb=GetObject (mypath & amp; "" & amp; Myfile) 'dir find the contents of the workbook, set to wb
With wb. Sheets (1) 'to find the workbook sheet1 operate
'copy wb sheet1 in addition to the first line of all content
. UsedRange. Offset (1, 0). Copy Sheet1, Range (" A "& amp; Sheet1. UsedRange. Rows. Count + 1)
End With

Wb. Close False 'Close the wb workbook and not save
End the If
Myfile=Dir 'looking for the next Excel workbook
Loop
Application. ScreenUpdating=True 'recovery screen update

End Sub



Pray god help solve how to change the code

CodePudding user response:

Open loop one by one, copy all the contents out,
  •  Tags:  
  • VBA
  • Related