Solved

Create a name for sheet

Posted on 2015-02-12
4
70 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
[X]
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
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 500 total points
ID: 40605422
Try this before the "End With":

ResultSheet.name = "hello"
0
 
LVL 34

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

615 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