Hi
I'm using the below code to copy data from multiple spreadsheets into a master spreadsheet. It works fine but I want to add a column (F) to state which workbook it was copied from. can some one please help me with that.
so if data was copied from workbook1 column F would say workbook1.
I'm using the below code to copy data from multiple spreadsheets into a master spreadsheet. It works fine but I want to add a column (F) to state which workbook it was copied from. can some one please help me with that.
so if data was copied from workbook1 column F would say workbook1.
Code:
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Dim i As Long
i = 999999
Range("A2:G" & i).Clear 'ClearContents
Const strPath As String = "Link Here"
ChDir strPath
strExtension = Dir("*.xlsx")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("CASE LOG").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets("CASE LOG").Range("A3:E" & LastRow).Copy wkbDest.Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub