Hi all,
I have a workbook we use at work for a daily log and there are two versions - there is a Day and Night version. In this workbook is a worksheet called "Handover" that we copy from Day to Night work book and so on... I've put a button in to each workbook and attached a vba code to it that copies the "Handover" worksheet, opens the Night workbook, pastes the "Handover" sheet in to the Night workbook and then saves this workbook and close it.
The issue I have is that if a colleague presses the button multiple times then Excel copies the "Handover" sheet multiple times in to the Night workbook.... not knowing that the "Handover" worksheet has already been copied and pasted. This results in multiple "Handover" sheets (Handover2, Handover3) ect...
Would anyone be able to help as I'd like the vba code to be able to check if the "Handover" sheet already exists in the closed workbook and if so Excel doesn't copy the "Handover" sheet again and shows a message box saying it already exists.
Ive attached the vba code that was written for me - I'd really appreciate any help
I have a workbook we use at work for a daily log and there are two versions - there is a Day and Night version. In this workbook is a worksheet called "Handover" that we copy from Day to Night work book and so on... I've put a button in to each workbook and attached a vba code to it that copies the "Handover" worksheet, opens the Night workbook, pastes the "Handover" sheet in to the Night workbook and then saves this workbook and close it.
The issue I have is that if a colleague presses the button multiple times then Excel copies the "Handover" sheet multiple times in to the Night workbook.... not knowing that the "Handover" worksheet has already been copied and pasted. This results in multiple "Handover" sheets (Handover2, Handover3) ect...
Would anyone be able to help as I'd like the vba code to be able to check if the "Handover" sheet already exists in the closed workbook and if so Excel doesn't copy the "Handover" sheet again and shows a message box saying it already exists.
Ive attached the vba code that was written for me - I'd really appreciate any help
VBA Code:
Sub CopySheetDaytoNight()
'Handover Copy Day to Night
Dim Ws As Worksheet
Set Ws = Worksheets("Handover")
Application.ScreenUpdating = False
With Workbooks.Open(Replace(ActiveWorkbook.FullName, " Day.", " Night."))
Ws.Copy , .Sheets("Closures")
.Close True
End With
Application.ScreenUpdating = True
Set Ws = Nothing
MsgBox "Handover Sheet Copied"
End Sub