Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a name for sheet

Posted on 2015-02-12
4
Medium Priority
?
72 Views
Last Modified: 2015-02-12
Hi,

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")
         .Move
        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
             .Parent.Activate
         End With
            ResultSheet.Columns("H:K").Delete
             ResultSheet.Columns("D").Delete
           Application.DisplayAlerts = False
            PivotSheet.Delete
            Application.DisplayAlerts = True
     
     End With


 End Sub





Regards,

Marcell
Tracker-1-.xlsm
0
Comment
Question by:Marcell999
4 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40605421
After this line in your existing code:
Set PivotSheet = ActiveSheet
Add this line:
pivotsheet.name = "AnyLegalWorksheetName"
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40605422
Try this before the "End With":

ResultSheet.name = "hello"
0
 
LVL 35

Expert Comment

by:Norie
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

0
 

Author Closing Comment

by:Marcell999
ID: 40605459
Phillip you are the boss!!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
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…

783 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