Vba help. copying data from several excel files and appending to one sheet

teefi

New Member
Joined
Jun 20, 2013
Messages
5
hello all!
I'm in need of some assistance please.
I regularly copy data from several excel files (one sheet) into one master sheet.
i have been looking to autonate this via a macro but am stuck!
the structure of the macro i believe to be:
1 Select files
2 create new file (excel)
3 copy and append data from each file into the new file ( variable)

all the files will have the same number of columns but will have unknown amount of rows.

i have seen variations of this but can't apply to what my issue.

can anyone help?

thanks in advance
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This is set up for .xml files, just change the extenstion as you need, along with the other variable that apply to you.
HTML:
'==========================
' Procedure  : FileLoop
' Date       : 18/11/12
' Author     :
' Phone      :
' Description: Loop through each file in folder
'--------------------------
Sub FileLoop()
    
    Dim oWbk As Workbook
    Dim sFil As String
    Dim sPath As String
    Dim OpenWB As Workbook
    Dim CodeWB As Workbook
    Dim SalesWB As Workbook
    Dim LR As Long
    Dim LR2 As Long
    
    Set CodeWB = ActiveWorkbook
    
    'Folder Location
    sPath = "O:\ORC Finance\Macros & SQL & Access\Macros\XML\Web Store Files\"
    
    ChDir sPath
    
    'Find only xml files
    sFil = Dir("*.xml") 'change or add formats
        
        'Loop through all files in foler
        Do While sFil <> ""
        
        'Delete and Enter New import sheet - as re-using xml maps is problmeatic
        Application.DisplayAlerts = False
        Sheets("Import Data").Delete
        Application.DisplayAlerts = True
        
        Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "Import Data"
        
        ActiveWorkbook.XmlImport URL:= _
        sPath & "\" & sFil _
        , ImportMap:=Nothing, Overwrite:=True, Destination:=Range("$A$1")
        
            
        LR = Range("A" & Rows.Count).End(xlUp).Row
        
        If LR > 1 Then
            Range("A2:A" & LR).EntireRow.Copy
        Else
            Range("A1:A" & LR).EntireRow.Copy
        End If
        
        
        'Paste sales lines in Data sheet in the codewb
        Sheets("Data").Select
        LR2 = Range("A" & Rows.Count).End(xlUp).Row
        Range("A" & LR2 + 1).EntireRow.Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        
 

        sFil = Dir
    Loop
End Sub
 
Upvote 0
thanks for this.
However, even with my edits i can't get it to work. i am still a novice in vba so don't really know where i am going wrong!
i have added the location of the folder but it doesnt open any files.it just selectsba row of cells in a blanksheet where the code is.
 
Upvote 0

Forum statistics

Threads
1,215,966
Messages
6,127,975
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top