VBA: Import multiple excel data (.xls) into a single worksheet

Ouble

New Member
Joined
Nov 30, 2015
Messages
18
Hi all, Ive came up with the VBA to import multiple excel data (.xls) into a single worksheet. However, the format is still not what I want. Could someone please help? I am still working on my VBA skills.

1. Currently, the VBA imports all the columns. I would only need column A and B. The data to appear from row 2 onwards.

2. Since im only importing 2 columns, I would like the data from...
excelfile 1, to appear at column A2 & B2
excelfile 2, to appear at column D2 & E2
excelfile 3, to appear at column G2 & H2
etc...

3. I would like the imported filename to appear at row1. eg. excelfile 1 (at A1), excelfile 2 (at D2), excelfile 3 (at G2)...etc...

4. Currenlt when i run the codes, the new data is being imported below the previous import. I would like the new import to overwrite the old imported data.

5. Kindly help

Code:
Sub ImportFiles()
    Dim Fldr As String, FN As String
    Dim wsDst As Worksheet, rngDst As Range
     
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count = 0 Then
            MsgBox "cancelled by user"
            Exit Sub
        End If
        Fldr = .SelectedItems(1)
    End With
     
    
    Set wsDst = ThisWorkbook.Sheets("Sheet1")
    FN = Dir(Fldr & "\*.xls", vbNormal)
    Do While FN <> ""
        Workbooks.OpenText Filename:=Fldr & "\" & FN, Space:=False
        
        Set rngDst = wsDst.Range("A" & wsDst.Rows.Count).End(xlUp).Offset(2)
        ActiveSheet.UsedRange.Copy rngDst
        FN = Dir()
        ActiveWorkbook.Close False
    Loop
End Sub


Any help is greatly appreciated! Thanks!

Ouble
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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