ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
Hello there. Good day, I'm having problem running my code wherein I have to copy some data from another workbook and after copying needed data, I just want to close it immediately without saving.
Here's my code:
Here's my code:
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
Workbooks(MyFile).Close SaveChanges:=False
End Sub