Greetings all
I have a report that I generate every week that uses a pivot table to aggregate data which I take and massage into the format for the report. Once formatted, the sheet (Data Staging) is copied to a new sheet and named Six Month Rpt mmddyy. That works fine until someone asks for a report that has already been generated (possibly some bad data was corrected or more likely someone couldn't find the printout on the network drive). At any rate, what I am wanting to do, is insert a test to see if this worksheet name exists in the workbook and either overwrite, or prompt for a new name. While either of these options are workable, it would be preferable to prompt for a new name.
I would certainly appreciate any help!
Thanks
Jacob
I have a report that I generate every week that uses a pivot table to aggregate data which I take and massage into the format for the report. Once formatted, the sheet (Data Staging) is copied to a new sheet and named Six Month Rpt mmddyy. That works fine until someone asks for a report that has already been generated (possibly some bad data was corrected or more likely someone couldn't find the printout on the network drive). At any rate, what I am wanting to do, is insert a test to see if this worksheet name exists in the workbook and either overwrite, or prompt for a new name. While either of these options are workable, it would be preferable to prompt for a new name.
I would certainly appreciate any help!
Code:
Sub SixMonthRpt()
Dim EDate As Date
Dim HDate As Date
Dim Msg As String
Dim wsSheet As Worksheet
Dim wsName As String
Dim lrowDS As Long
Dim lrowPT As Long
EDate = Application.InputBox _
(prompt:="Enter Report Date Here.", _
Title:="Report Date Input Box", Type:=1)
HDate = EDate - 180
wsName = "Six Month Rpt " & Format(EDate, "mmddyy")
Msg = "Do you wish to run the Six Month Production Summary Report?"
Msg = Msg & vbNewLine & vbNewLine & vbNewLine
Msg = Msg & "The Beginning date for report will be " & HDate & vbNewLine
Msg = Msg & "Ending date will be " & EDate & vbNewLine & vbNewLine
Title = "Confirm Report Date Range"
config = vbYesNo + vbQuestion
ans = MsgBox(Msg, config, Title)
If ans = vbNo Then
MsgBox "This Report has been TERMINATED by USER"
Exit Sub
End If
' Bunch of code formatting the data and such not
ActiveWorkbook.Sheets("Data Staging").Copy after:=ActiveWorkbook.Sheets("Data Staging")
ActiveSheet.Name = wsName
Exit Sub
Thanks
Jacob