Re: Macro: Copy Cells To Another Workbook On Closing
Hello Dave,
Working on Excel 2010, I I tried to make good use of the code above but I believe something goes wrong. I modified :
- name of the file
- path folder
- range to copy
- The name of the sheet "Sheet1" with the codename of the Worksheet I have
Here it's how it looks like :
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wbTH As Workbook
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error Resume Next
Set wbTH = Workbooks("NYP_Late PO.xlsm")
On Error GoTo 0
If wbTH Is Nothing Then
Set wbTH = Workbooks.Open _
(Filename:="c:\My Documents\NYP_Late PO.xlsm")
End If
With Me.Sheet("Cancelled")
.Range("A1:L500").Copy _
Destination:=wbTH.Sheets(1).Range("A" & Rows.Count).End(xlUp)(2, 1)
End With
wbTH.Close SaveChanges:=True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Display More
Is there a step missing ?
Thanks for your help.
Ben