ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
Hello, as you can see from the code below I have set the last row of "column A" as the last row of data to be copied. To be more specific, column A has 288 rows while column D has 700 rows because it contains formula that refers to column C of the workbook where the data are being copied from. However, I'm having problem on pasting needed data on my summary workbook because Column D hast 288 rows but Column F contains 700 rows same as number of rows from workbook of raw data.
VBA Code:
Sub Test1()
Application.ScreenUpdating = False
Dim lastrow As Long, srcWB As Workbook, desWS As Worksheet
Dim MyLoc As String, MyFile As String
Dim wb As Workbook
MyLoc = "C:\Users\ADMIN\Desktop\Samples\" & ThisWorkbook.Sheets("data").Range("A3").Value & "\AllProcess\Process1\"
MyFile = MyLoc & ThisWorkbook.Sheets("data").Range("B5").Value
Set wb = Workbooks.Open(MyFile)
Set srcWB = wb
Set desWS = ThisWorkbook.Sheets("Process1")
With srcWB
With .Sheets("SEMI")
lastrow = .Range("E" & .Rows.Count).End(xlUp).Row
.Range("A2:A" & lastrow).Copy
desWS.Cells(desWS.Rows.Count, "D").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Range("D2:D" & lastrow).Copy
desWS.Cells(desWS.Rows.Count, "F").End(xlUp).Offset(1).PasteSpecial xlPasteValues
Workbooks(MyFile).Close SaveChanges:=False
End Sub