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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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…

751 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