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
Any help is greatly appreciated! Thanks!
Ouble
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