Results 1 to 5 of 5

Thread: How to use DataBodyRange property to write to a specific sheet?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Jan 2010
    Posts
    13
    Location

    How to use DataBodyRange property to write to a specific sheet?

    Hi,

    I am new to VBA programming. I got this code snippet and it reads a pivot table and it CREATES A NEW WORKSHEET in the workbook and then writes the content to it. I want to know how I can modify this code to write to a specific sheet in the same workbook. Like for example, I want the contents to write to a specific sheet "Results_Obtained" in the same workbook. Is there any option ? Here is the code snippet.

     
    For Each pvt In ActiveSheet.PivotTables
        With pvt
            .ColumnGrand = True
            .RowGrand = True
        End With
        Set rng = pvt.DataBodyRange
        rng.Cells(rng.Rows.Count, rng.Columns.Count).ShowDetail = True
    Next pvt
    My Pivot Table looks like the one I have put in the attachment (vbacodehelp.xls). It is in the sheet PivotTable.




    From the code snippet I have provided above, the output I get perfectly is as shown in the attachement (Sheet from code snippet).

    The only problem is, the code writes to a new sheet, rather than a sheet which I want to. Can someone help. Thanks

    Edit: Vba tags added to code. Select your code when posting and hit the vba button to format it for the forum.
    Last edited by Aussiebear; 02-05-2025 at 01:34 AM. Reason: The copy and paste of the excel content does not show correct. Including them as an attachment

Posting Permissions

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