+ Reply to Thread
Results 1 to 13 of 13

Pivot Details into New WorkBook

Hybrid View

  1. #1
    Registered User
    Join Date
    11-04-2010
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Lightbulb Pivot Details into New WorkBook

    Hello,

    Just got my first problem solved and another one arises. (Thanks again to DonkeyOte)

    So with the code below I can now get pivot details with a mouse click and simultenously it deletes "unwanted" columns. This works perfectly.

    Now my question is : can I get pivot details open into new workbook rather than ?

    If this is possible, then the second question is as follows :

    This is not mandatory, but would be really cool.
    Is there a way to give the new workbook a name ? ideally it would be Waste Proposal + Current datetime.

    Sub Hylkyehdotus()
    '
    ' Hylkyehdotus Macro
    '
    
        Dim rngArea As Range
        With Sheets("TOY Mill Stocks").PivotTables("PivotTable2").TableRange1
            .Cells(.Cells.Count).ShowDetail = True
            For Each rngArea In Range("B:B,E:G,J:J,L:AZ,BB:BG").Areas
                rngArea.Delete
            Next rngArea
        End With
              
    End Sub
    Last edited by Magerator; 11-05-2010 at 07:48 AM. Reason: Tried to add the code tags...don't know if it's right now

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot Details into New WorkBook

    AFAIK you can't get the drill through to open in a new workbook automatically... you can however use code however to move the sheet to a new book as part of the routine:

    Sub Hylkyehdotus()
        Dim rngArea As Range
        With Sheets("TOY Mill Stocks").PivotTables("PivotTable2").TableRange1
            .Cells(.Cells.Count).ShowDetail = True
            ActiveSheet.Move
            For Each rngArea In Range("B:B,E:G,J:J,L:AZ,BB:BG").Areas
                rngArea.Delete
            Next rngArea
        End With          
    End Sub
    (point being when the drilldown is activated the detail sheet becomes the active sheet)

    In terms of file name - yes that's possible but where do you wish to save it ?

  3. #3
    Registered User
    Join Date
    11-04-2010
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Pivot Details into New WorkBook

    Hey,

    Thanks for the reply. Don't have the file with me now, I'm not at the office anymore. I will test first thing tomorrow morning.

    About that file name and save location, that's yet to be decided where this file will be saved, but it will be a network drive.
    If that is possible to save on a network drive will it make any difference if we refer it to with UNC-path or just a letter mapped to the drive.
    So it will start either with Y:\ or with UNC path \\servername\and so on...

    I will revert tomorrow,

    Jyri
    Last edited by DonkeyOte; 11-04-2010 at 12:28 PM. Reason: removed unnecessary quote

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot Details into New WorkBook

    UNC is always best given it's possible (if not desired) for different clients to use different mappings.

  5. #5
    Registered User
    Join Date
    11-04-2010
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Pivot Details into New WorkBook

    Quote Originally Posted by DonkeyOte View Post
    UNC is always best given it's possible (if not desired) for different clients to use different mappings.
    Morning,

    Okay the code works just as wanted, as usual

    I have just talked with our Business Controller and she asked if this scenario would be possible :

    1) User clicks on a macro it will open up a new workbook, let's say "WasteProposal.xls" and pivot details is copied there.
    (This is allready done by you, just without that naming and saving.)

    2) Every new waste proposal is copied to that same file(WasteProposal.xls) to the same sheet(WasteProposals), but they are just copied right after each other(couple of empty lines in between).

    3) Could we get a timestamp and windows username to each proposal too.

    End result would look something like I put in attached file.


    Thank you again.

    Jyri
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-04-2010
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Pivot Details into New WorkBook

    Quote Originally Posted by DonkeyOte View Post
    UNC is always best given it's possible (if not desired) for different clients to use different mappings.
    And the save location for that file would be : \\servername\yhteiset\Wasteproposals

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot Details into New WorkBook

    In reality - untested:

    Sub Hylkyehdotus()
        Dim rngArea As Range
        Dim strPath As String
        Dim vData As Variant
        On Error GoTo Handler
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
            .DisplayAlerts = False
        End With
        strPath = "\\servername\yhteiset\Wasteproposals.xls"
        With Sheets("TOY Mill Stocks").PivotTables("PivotTable2").TableRange1
            .Cells(.Cells.Count).ShowDetail = True
            For Each rngArea In Range("B:B,E:G,J:J,L:AZ,BB:BG").Areas
                rngArea.Delete
            Next rngArea
            vData = ActiveSheet.UsedRange
            Workbooks.Open strPath
            With Sheets("Wasteproposals")
                With .Cells(.Rows.Count, "A").End(xlUp).Offset(2)
                    .Resize(UBound(vData, 1), UBound(vData, 2)) = vData
                    With .Offset(2, 8).Resize(3)
                        .Value = Application.Transpose(Array("Timestamp:", "Username", "Computer Name"))
                        .Offset(, 2).Value = Application.Transpose(Array(Now, Environ("username"), Environ("computername")))
                    End With
                End With
            End With
            ActiveWorkbook.Close True
            ActiveSheet.Delete
        End With
    ExitPoint:
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
            .DisplayAlerts = True
        End With
        Exit Sub
        
    Handler:
        MsgBox "Error Has Occurred" & vbLf & vbLf & _
            "Error Number: " & Err.Number & vbLf & vbLf & _
            "Error Desc.: " & Err.Description, _
            vbCritical, _
            "Fatal Error"
        Resume ExitPoint
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1