Create a name for sheet

Posted on 2015-02-12
Last Modified: 2015-02-12

Please see attached file. I would like to add to the existing code below to create a name for the new sheet as part of the code:

Sub Button1_Click()

  Dim Pivot_trans As Boolean
  Dim ResultSheet
 Dim PivotSheet
     With Sheets.Add
         Sheets("Pivot (3)").PivotTables(1).TableRange2.Copy .Range("A1")
        Set PivotSheet = ActiveSheet
         With ActiveSheet.PivotTables(1)
             Pivot_trans = .ColumnGrand
             .ColumnGrand = True
             .Parent.Cells.SpecialCells(xlCellTypeLastCell).ShowDetail = True
            Set ResultSheet = ActiveSheet
             .ChangePivotCache ActiveWorkbook.PivotCaches.Create(xlDatabase, Selection, xlPivotTableVersion14)
             .ColumnGrand = Pivot_trans
         End With
           Application.DisplayAlerts = False
            Application.DisplayAlerts = True
     End With

 End Sub


Question by:Marcell999
LVL 18

Expert Comment

ID: 40605421
After this line in your existing code:
Set PivotSheet = ActiveSheet
Add this line: = "AnyLegalWorksheetName"
LVL 24

Accepted Solution

Phillip Burton earned 500 total points
ID: 40605422
Try this before the "End With": = "hello"
LVL 33

Expert Comment

ID: 40605425
How about starting the code like this?
Sub Button1_Click()

  Dim Pivot_trans As Boolean
  Dim ResultSheet
 Dim PivotSheet
    Set ResultSheet = Sheets.Add  
     With ResultSheet
         .Name = "Results" ' change as required 
         Sheets("Pivot (3)").PivotTables(1).TableRange2.Copy .Range("A1")

Open in new window


Author Closing Comment

ID: 40605459
Phillip you are the boss!!!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question