Consolidate data from files

Sachinaddi

New Member
Joined
Jan 30, 2025
Messages
5
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
Need to copy data from 12 files named 1 to 12
all files are saved in a folder name "Files"
all file name are 1 to 12
all files having same tab name
all tabs have same colmn range "A to U" but row range are different
need to copy data from tab named "B2B" from A6 to U6
and paste in file name "combined" in same folder and tab name B2B
after pasting data need to add file name at the end of column V6 in all rows
data to be be paste from other file at the end of 1st file data paste and so on
 
1739882237494.png
 
Upvote 0
try
Rich (BB code):
Sub test()
    Dim myDir$, fn$, i&, s$, LR&, wb As Workbook
    Const wsName$ = "B2B", r$ = "A6:U6", wbName$ = "combined"
    With Application.FileDialog(msoFileDialogFolderPicker)
        If .Show Then myDir = .SelectedItems(1) & "\"
    End With
    If myDir = "" Then Exit Sub
    fn = Dir(myDir & wbName & ".xls*")
    If fn = "" Then MsgBox "No workbook named " & wbName & " found", vbCritical: Exit Sub
    Application.ScreenUpdating = False
    Set wb = Workbooks.Open(myDir & fn)
    wb.Sheets(wsName).[a1].CurrentRegion.Offset(1).ClearContents
    For i = 1 To 12
        fn = Dir(myDir & i & ".xls*")
        If fn <> "" Then
            LR = wb.Sheets(wsName).Evaluate("max(if(a1:t100<>"""",row(1:100)))") + 1
            s = "'" & myDir & "[" & fn & "]" & wsName & "'!" & Split(r, ":")(0)
            With wb.Sheets(wsName).Cells(LR, 1).Resize(Range(r).Rows.Count, Range(r).Columns.Count)
                .Formula = "=if(" & s & "<>""""," & s & ","""")"
                .Value = .Value
                .Columns(.Columns.Count + 1) = fn
            End With
        End If
    Next
    wb.Close True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,924
Members
453,767
Latest member
922aloose

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