ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
Hi. I have here a code that I need to do some tweaking. My problem is what additional code is appropriate wherein I could copy the Sheet Names where the data came from (srcWB) into the destination file (desWS).
Here's a sample of the desired output, also see below code for reference. Thanks!
Here's a sample of the desired output, also see below code for reference. Thanks!
VBA Code:
Private Sub CopyEachPrcs()
Application.ScreenUpdating = False
Dim lastRow As Long, srcWB As Workbook, desWS As Worksheet
Set srcWB = ThisWorkbook
Set desWS = Workbooks("final data.xlsm").Sheets(1)
With srcWB
With .Sheets(1)
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A2:C" & lastRow).Copy
desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
With .Sheets(2)
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("B2:B" & lastRow).Copy
desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Range("A2:A" & lastRow).Copy
desWS.Cells(desWS.Rows.Count, "B").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Range("C2:C" & lastRow).Copy
desWS.Cells(desWS.Rows.Count, "C").End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub