EasyManua.ls Logo

Amazon VBA User Manual

Amazon VBA
60 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #45 background imageLoading...
Page #45 background image
275
Using Advanced Pivot Table Techniques
WSR.Cells(LastRow, 1).Value = “Top 5 Total”
‘ Do some basic formatting
‘ Autofit columns, bold the headings, right-align
WSR.Range(WSR.Range(“A2”), WSR.Cells(LastRow, 8)).Columns.AutoFit
Range(“A3”).EntireRow.Font.Bold = True
Range(“A3”).EntireRow.HorizontalAlignment = xlRight
Range(“A3”).HorizontalAlignment = xlLeft
Range(“B3”).Value = “Revenue”
Range(“A2”).Select
Next PivItem
‘ Clear the pivot table
PT.TableRange2.Clear
Set PTCache = Nothing
MsgBox Ctr & “ Region reports have been created”
End Sub
Manually Filtering Two or More Items in a PivotField
In addition to setting up a calculated pivot item to display the total of a couple of products
that make up a dimension, you can manually filter a particular PivotField.
For example, you have one client who sells shoes. In the report showing sales of sandals, he
wants to see just the stores that are in warm-weather states. The code to hide a particular
store is
PT.PivotFields(“Store”).PivotItems(“Minneapolis”).Visible = False
You need to be very careful never to set all items to False; otherwise, the macro ends with
an error. This tends to happen more than you would expect. An application may first show
products A and B and then on the next loop show products C and D. If you attempt to make
A and B not visible before making C and D visible, no products will be visible along the
PivotField, which causes an error. To correct this, always loop through all PivotItems, mak-
ing sure to turn them back to visible before the second pass through the loop.
This process is easy in VBA. After building the table with
Product in the page field, loop
through to change the
Visible property to show only the total of certain products:
‘ Make sure all PivotItems along line are visible
For Each PivItem In _
PT.PivotFields(“Product”).PivotItems
PivItem.Visible = True
Next PivItem
‘ Now - loop through and keep only certain items visible
For Each PivItem In _
PT.PivotFields(“Product”).PivotItems
Select Case PivItem.Name
Case “Landscaping/Grounds Care”, _
“Green Plants and Foliage Care”
11
12_0789736012_CH11.qxd 12/11/06 6:26 PM Page 275
Question and Answer IconNeed help?

Do you have a question about the Amazon VBA and is the answer not in the manual?

Amazon VBA Specifications

General IconGeneral
BrandAmazon
ModelVBA
CategorySoftware
LanguageEnglish

Summary

Using VBA to Create Pivot Tables

Introducing VBA

Introduction to Visual Basic for Applications (VBA) as a powerful Excel macro language for automation.

Enabling VBA in Your Copy of Excel

Steps to activate VBA macros through Excel's Trust Center settings for security.

Visual Basic Editor

Overview of the VBE interface, including Project Explorer and Code Window.

Visual Basic Tools

Key VBE features like AutoComplete and F1 help for coding.

Learning Tricks of the Trade

Writing Code to Handle Any Size Data Range

Techniques for dynamic range selection using `Cells` and `Resize`.

Understanding Versions

Differences in VBA pivot table methods across Excel versions.

Building a Pivot Table in Excel VBA

Getting a Sum Instead of a Count

Ensuring correct aggregation functions like `xlSum` are explicitly applied in VBA.

Determining Size of a Finished Pivot Table

Using `TableRange2` and `Offset` for accurate pivot table manipulation.

Creating a Report Showing Revenue by Product

Eliminating Blank Cells in the Values Area

Replacing blank pivot table cells with zero using the `NullString` property in VBA.

Controlling the Sort Order with AutoSort

Implementing custom sort orders for pivot table fields via VBA using the `AutoSort` method.

Suppressing Subtotals for Multiple Row Fields

Disabling automatic subtotals for specific pivot fields by setting the `Subtotals` property.

Handling Additional Annoyances When Creating Your Final Report

Creating a Summary on a Blank Report Worksheet

Copying pivot table data as static values to a new sheet for final reporting.

Filling the Outline View

Filling blank cells in column A of the report for consistent presentation and formatting.

Adding Subtotals

Programmatically adding subtotals and page breaks to pivot table reports using VBA.

Addressing Issues with Two or More Data Fields

Calculated Data Fields

Creating custom fields in pivot tables using formulas within VBA.

Calculated Items

Defining new items within a field for combined calculations and analysis.

Summarizing Date Fields with Grouping

Group by Week

Grouping date data by week using VBA's date grouping features.

Using Advanced Pivot Table Techniques

Using AutoShow to Produce Executive Overviews

Filtering pivot tables to display top N records efficiently using the `AutoShow` method.

Using ShowDetail to Filter a Recordset

Drilling down into pivot table cells to view underlying source data records.

Creating Reports for Each Region or Model

Generating individual reports for each item in a page field, like regions or models.

Using New Pivot Table Features in Excel 2007

Using the New Filters

Applying advanced filters (label, date, value) to pivot tables using VBA in Excel 2007.

Applying a Table Style

Formatting pivot tables with predefined styles and layout options via VBA.

Applying a Data Visualization

Incorporating visual elements like data bars into pivot tables using VBA.

Understanding Special Considerations for Excel 97

Pivot Table Code for Excel 97 Users

Using the `PivotTableWizard` method for creating pivot tables compatible with Excel 97.

Next Steps

Related product manuals