Hello Excel Expert,
I found the below code in this forum and with little amendment I brought it into my work.
Sub CombineAll()
Application.ScreenUpdating = False
Dim MAlrow, MElrow, MSlrow As Long
Dim Fpath As String
Dim Fname As String
MAlrow = Sheets("Arrangment").Range("A65336").End(xlUp).Row
MElrow = Sheets("Request").Range("A65336").End(xlUp).Row
MSlrow = Sheets("Status").Range("A65336").End(xlUp).Row
Fpath = "C:\Users\ImUser\Desktop\Testingsss\" ' change to your directory
Fname = Dir(Fpath & "*.xlsx")
Do While Fname <> ""
Workbooks.Open Fpath & Fname
Worksheets("Arrangment").Activate
Range("A2", Selection.End(xlDown)).Select '' This assumes header in first row
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy Destination:=Workbooks("Master.xlsm").Sheets("Arrangment").Cells(MAlrow + 1, 1)
Worksheets("Request").Activate
Range("A2", Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy Destination:=Workbooks("Master.xlsm").Sheets("Request").Cells(MElrow + 1, 1)
Worksheets("Status").Activate
Range("A2", Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy Destination:=Workbooks("Master.xlsm").Sheets("Status").Cells(MSlrow + 1, 1)
Workbooks(Fname).Close SaveChanges:=False
Fname = Dir
''' Lets get the last row for the next copy/paste '''
MAlrow = Sheets("Arrangment").Range("A65336").End(xlUp).Row
MElrow = Sheets("Request").Range("A65336").End(xlUp).Row
MSlrow = Sheets("Status").Range("A65336").End(xlUp).Row
Loop
Application.ScreenUpdating = True
End Sub
What I need is that it starts copying data from Column "B2" and in Column "A2" it fills the name of Workbook using wildcard. Like if the file name is
"ABCDEFGH-XXXXXXX-XXXXXXX-DF-memory-insight". then i need it fills "ABCDEFGH" in the column A parallel with the number of records.
If the last used row is "B2:B15" then it should fill the worksheet name using wild card from range "A2:A15".
Can anyone help me with this!
Bookmarks