Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How can I alter this Macro?

All,

This is some code which I belive Debra Dalgleish supplied for me some
time back.

I am wondering how I can manipulate it for the following situations.

Only one worksheet
Only one Pivottable
Only one Field

I have tried to alter it myself but have had no luck with the nested
With's and such.


The Code:

Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim i As Integer

On Error Resume Next
For i = 1 To 2
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next
Next
pt.RefreshTable
Next
Next
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How can I alter this Macro?

Untested!


Option Explicit
sub aaa()

Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim i As Integer

set ws = worksheets("sheet1")
set pt = ws.pivottables("pivottablenamehere")
set pf = pt.pivotfields("namehere")

On Error Resume Next
For i = 1 To 2
'For Each ws In ActiveWorkbook.Worksheets
' For Each pt In ws.PivotTables
' For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next
' Next
pt.RefreshTable
' Next
'Next
Next
End Sub

wrote:

All,

This is some code which I belive Debra Dalgleish supplied for me some
time back.

I am wondering how I can manipulate it for the following situations.

Only one worksheet
Only one Pivottable
Only one Field

I have tried to alter it myself but have had no luck with the nested
With's and such.

The Code:

Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim i As Integer

On Error Resume Next
For i = 1 To 2
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next
Next
pt.RefreshTable
Next
Next
Next
End Sub


--

Dave Peterson
Reply
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
alter column ref Kaz Excel Discussion (Misc queries) 3 April 27th 10 02:55 AM
Alter data or start macro from a date formula DavidM Excel Programming 2 August 3rd 05 06:24 PM
macro to alter worksheet code cwwolfdog Excel Programming 1 March 31st 05 03:29 PM
how to alter the date within a macro LWhite Excel Discussion (Misc queries) 2 January 4th 05 01:54 PM
Alter existing code gav meredith Excel Programming 5 April 20th 04 09:03 AM


All times are GMT +1. The time now is 05:59 PM.

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

About Us

"It's about Microsoft Excel"