I've run into an issue that seems to be straight forward, but for whatever reason, is giving me an error message in my code. I'm using a Macro to create a Pivot Table and would like to rename the sheet that is created for the Pivot Table. My only problem is that the active sheet will not rename and error message "Run-time 9: Subscript out of range" is given . The code is below and the error occurs on the last line:
Sub Macro24()
Dim VendorData As String
Dim Lastrow As Long
Dim PivotSheet As String
Sheets("Statement").Select
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Statement").Select
ActiveWorkbook.Names.Add Name:="VendorData", RefersTo:= _
"=Statement!$A$4:$C$" & Lastrow
Sheets.Add
PivotSheet = ActiveSheet.Name