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 #4 background imageLoading...
Page #4 background image
Despite the aforementioned error checking, Excel may still encounter an error at run-
time. If this happens, click the Debug button. The line that caused the error is high-
lighted in yellow. Hover your mouse cursor over any variable to see the current value of
the variable.
When you are in Debug mode, use the Debug menu to step line by line through code.
You can toggle back and forth between Excel and VBA to see the effect of running a
line of code on the worksheet.
Other great debugging tools are breakpoints, the Watch window, the Object Browser,
and the Immediate window. Read about these tools in the Excel VBA Help menu.
The Macro Recorder
Excel offers a macro recorder that is about 90% perfect. Unfortunately, the last 10% is frus-
trating. Code that you record to work with one dataset is hard-coded to work only with that
dataset. This behavior might work fine if your transactional database occupies cells
A1:K415501 every single day, but if you are pulling in a new invoice register every day, it is
unlikely that you will have the same number of rows each day. Given that you might need to
work with other data, it would be a lot better if Excel could record selecting cells using the
End key. This is one of the shortcomings of the macro recorder.
In reality, Excel pros use the macro recorder to record code but then expect to have to clean
up the recorded code.
Understanding Object-Oriented Code
VBA is an object-oriented language. Most lines of VBA code follow the Noun.Verb syntax.
However, in VBA, it is called
Object.Method. Objects can be workbooks, worksheets, cells,
or ranges of cells. Methods can be typical Excel actions, such as
.Copy, .Paste, and
.PasteSpecial.
Many methods allow adverbs—parameters you use to specify how to perform the method. If
you see a construct with a colon/equal sign, you know that the macro recorder is describing
how the method should work.
You also might see the type of code in which you assign a value to the adjectives of an
object. In VBA, adjectives are called properties. If you set
ActiveCell.Font.ColorIndex = 3,
you are setting the font color of the active cell to red. Note that when you are dealing with
properties, there is only an equal sign, not a colon/equal sign.
Learning Tricks of the Trade
You need to master a few simple techniques to be able to write efficient VBA code. These
techniques will help you make the jump to writing effective code.
Chapter 11 Using VBA to Create Pivot Tables
234
11
12_0789736012_CH11.qxd 12/11/06 6:26 PM Page 234
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