LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pivot Table changing sum values using VB

I have a pivot table that i am trying to copy out to another sheet.

A note of clarification.
My variables are used in the sum field - I have 70 different columns of
data, that I want to use in combination one column field and one row field.
So each time I'm changing the sum calculated by add a new sum and remove the
previous one.

I've tried to record the procedure to highlight a new variable and remove
the previous. However it doesn't seem to work.

I've seen a post that talks about calculated fileds but this isn't.

Any suggestions gratefully received.



Code:
Sub pivot1() 
     
    Dim j As Integer 
    Dim k As Integer 
    Dim i As Integer 
    Dim StrM As String ' new variable
    Dim StrM1 As String ' old variable
    Dim StrN As String 
    Dim theBook As Workbook 
    Dim theSheet As Worksheet 
    Dim theSheet1 As Worksheet 
     
     
    Set theBook =  ActiveWorkbook 
    Set theSheet = theBook.Sheets("Sheet4") ' this is where my data is
    Set theSheet1 = theBook.Sheets("Sheet3") ' this is where my new table is
     
    k = 2 ' column in my new table
    j = 1 
    For i = 1 To 70 
        StrM1 = StrM 
        StrM = "SCT43000" & j 
        StrN = "Sum of SCT43000" & j 
         
         
        If i < 2 Then 
            theSheet.PivotTables("PivotTable2").AddDataField 
theSheet.PivotTables( _ 
            "PivotTable2").PivotFields(StrM), StrN, xlSum 
        Else 
            theSheet.PivotTables("PivotTable2").AddDataField 
theSheet.PivotTables( _ 
            "PivotTable2").PivotFields(StrM), StrN, xlSum 
            
theSheet.PivotTables("PivotTable2").PivotFields(StrM1).Orientation = xlHidden 
        End If 
        theSheet. Range("B4:F637").Copy (theSheet1.Cells(1, k)) 
         
        j = j + 1 
        k = k + 5 
    Next i 
     
End Sub 
 
This Is the macro recorders code 
ActiveSheet.PivotTables("PivotTable2").PivotFields("SCT4300068").Orientation 
= xlHidden 
 ' this seems to remove the values but not as part of a macro.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying values from pivot table to cells outside pivot table richzip Excel Discussion (Misc queries) 4 January 16th 08 11:03 PM
Pivot Table - Changing Column Values WCM Excel Discussion (Misc queries) 2 April 20th 07 04:48 PM
Pivot Table changing itself? PaulW Excel Discussion (Misc queries) 1 February 16th 07 03:18 PM
Pivot Tables -changing datasource for exsting Pivot Table kfschaefer Setting up and Configuration of Excel 0 May 30th 06 06:36 PM
changing values in a Word Table Simon New Users to Excel 0 June 29th 05 10:28 AM


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"