You are on page 1of 99

Areas Object (Excel)

Office 2013 and later


Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of the areas, or contiguous blocks of cells, within a selection.

Remarks
Theres no singular Area object; individual members of the Areas collection are Range objects. The Areas
collection contains one Range object for each discrete, contiguous range of cells within the selection. If the
selection contains only one area, the Areas collection contains a single Range object that corresponds to that
selection.

Example
Use the Areas property to return the Areas collection. The following example clears the current selection if it
contains more than one area.

VBA
If Selection.Areas.Count <> 1 Then Selection.Clear

Use Areas(index), where index is the area index number, to return a single Range object from the collection. The
index numbers correspond to the order in which the areas were selected. The following example clears the first
area in the current selection if the selection contains more than one area.

VBA
If Selection.Areas.Count <> 1 Then
Selection.Areas(1).Clear
End If

Some operations cannot be performed on more than one area in a selection at the same time; you must loop
through the individual areas in the selection and perform the operations on each area separately. The following
example performs the operation named "myOperation" on the selected range if the selection contains only one
area; if the selection contains multiple areas, the example performs myOperation on each individual area in the
selection.

VBA
Set rangeToUse = Selection
If rangeToUse.Areas.Count = 1 Then
myOperation rangeToUse
Else
For Each singleArea in rangeToUse.Areas
myOperation singleArea
Next
End If

Properties
Name

Application

Count

Creator

Item

Parent

Areas.Application Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax
expression .Application

expression A variable that represents an Areas object.

Example
This example displays a message about the application that created myObject.

VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Areas.Count Property (Excel)
Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax
expression .Count

expression A variable that represents an Areas object.

Example
This example displays the number of columns in the selection on Sheet1. The code also tests for a multiple-area
selection; if one exists, the code loops on the areas of the multiple-area selection.

VBA
Sub DisplayColumnCount()
Dim iAreaCount As Integer
Dim i As Integer

Worksheets("Sheet1").Activate
iAreaCount = Selection.Areas.Count

If iAreaCount <= 1 Then


MsgBox "The selection contains " & Selection.Columns.Count & " columns."
Else
For i = 1 To iAreaCount
MsgBox "Area " & i & " of the selection contains " & _
Selection.Areas(i).Columns.Count & " columns."
Next i
End If
End Sub

reas.Creator Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax
expression .Creator

expression A variable that represents an Areas object.

Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

Areas.Item Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a single object from a collection.

Syntax

expression .Item(Index)

expression A variable that represents an Areas object.

Parameters
Name Required/Optional Data Type Description

Index Required Long The index number of the object.

Example

This example clears the first area in the current selection if the selection contains more than one area.

VBA

If Selection.Areas.Count <> 1 Then


Selection.Areas.Item(1).Clear
End If

Areas.Parent Property (Excel)


Office 2013 and later
Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax
expression .Parent

expression A variable that represents an Areas object.

utoCorrect Object (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Contains Microsoft Excel AutoCorrect attributes (capitalization of names of days, correction of two initial capital
letters, automatic correction list, and so on).

Example
Use the AutoCorrect property to return the AutoCorrect object. The following example sets Microsoft Excel to
correct words that begin with two initial capital letters.

VBA
With Application.AutoCorrect
.TwoInitialCapitals = True
.ReplaceText = True
End With
AutoCorrect.AddReplacement Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Adds an entry to the array of AutoCorrect replacements.

Syntax

expression .AddReplacement(What, Replacement)

expression A variable that represents an AutoCorrect object.

Parameters
Data
Name Required/Optional Description
Type

The text to be replaced. If this string already exists in the array of


What Required String AutoCorrect replacements, the existing substitute text is replaced by
the new text.

Replacement Required String The replacement text.

Return Value
Variant

Example

This example substitutes the word "Temp." for the word "Temperature" in the array of AutoCorrect replacements.

VBA

With Application.AutoCorrect
.AddReplacement "Temperature", "Temp."
End With

AutoCorrect.Application Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax
expression .Application

expression A variable that represents an AutoCorrect object.


Example
This example displays a message about the application that created myObject.

VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If

utoCorrect.AutoExpandListRange Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A Boolean value indicating whether automatic expansion is enabled for lists. When you type in a cell of an empty
row or column next to a list, the list will expand to include that row or column if automatic expansion is enabled.
Read/write Boolean.

Syntax
expression .AutoExpandListRange

expression A variable that represents an AutoCorrect object.

Example
The following example enables automatic expansion of lists when typing in adjacent rows or columns.

VBA
Sub SetAutoExpand

Application.AutoCorrect.AutoExpandListRange = TRUE

End Sub

AutoCorrect.AutoFillFormulasInLists Property
(Excel)
Office 2013 and later
Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Affects the creation of calculated columns created by automatic fill-down lists. Read/write Boolean.

Syntax
expression .AutoFillFormulasInLists

expression A variable that represents an AutoCorrect object.

Remarks
The property does not affect existing calculated columns or calculated columns created where auto-fill did not
occur.

utoCorrect.CapitalizeNamesOfDays Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if the first letter of day names is capitalized automatically. Read/write Boolean.

Syntax
expression .CapitalizeNamesOfDays

expression A variable that represents an AutoCorrect object.

Example
This example sets Microsoft Excel to capitalize the first letter of the names of days.

VBA
With Application.AutoCorrect
.CapitalizeNamesOfDays = True
.ReplaceText = True
End With

AutoCorrect.CorrectCapsLock Property (Excel)


Office 2013 and later
Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if Microsoft Excel automatically corrects accidental use of the CAPS LOCK key. Read/write Boolean.

Syntax
expression .CorrectCapsLock

expression A variable that represents an AutoCorrect object.

Example
This example enables Microsoft Excel to automatically correct accidental use of the CAPS LOCK key.

VBA
Application.AutoCorrect.CorrectCapsLock = True

AutoCorrect.CorrectSentenceCap Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if Microsoft Excel automatically corrects sentence (first word) capitalization. Read/write Boolean.

Syntax
expression .CorrectSentenceCap

expression A variable that represents an AutoCorrect object.

Example
This example enables Microsoft Excel to automatically correct sentence capitalization.

VBA
Application.AutoCorrect.CorrectSentenceCap = True

utoCorrect.Creator Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax
expression .Creator

expression A variable that represents an AutoCorrect object.

Remarks
If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

AutoCorrect.DeleteReplacement Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Deletes an entry from the array of AutoCorrect replacements.

Syntax

expression .DeleteReplacement(What)

expression A variable that represents an AutoCorrect object.

Parameters
Data
Name Required/Optional Description
Type

The text to be replaced, as it appears in the row to be deleted from the array
What Required String of AutoCorrect replacements. If this string doesn't exist in the array of
AutoCorrect replacements, this method fails.
Return Value
Variant

Example

This example removes the word "Temperature" from the array of AutoCorrect replacements.

VBA

With Application.AutoCorrect
.DeleteReplacement "Temperature"
End With

AutoCorrect.DisplayAutoCorrectOptions Property
(Excel)
Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Allows the user to display or hide the AutoCorrect Options button. The default value is True. Read/write Boolean.

Syntax
expression .DisplayAutoCorrectOptions

expression A variable that represents an AutoCorrect object.

Remarks
The DisplayAutoCorrectOptions property is a Microsoft Office-wide setting. Changing this property in
Microsoft Excel will affect the other Office applications also.

In Excel the AutoCorrect Options button only appears when a hyperlink is automatically created.

Example
This example determines if the AutoCorrect Options button can be displayed and notifies the user.

VBA
Sub CheckDisplaySetting()

'Determine setting and notify user.


If Application.AutoCorrect.DisplayAutoCorrectOptions = True Then
MsgBox "The AutoCorrect Options button can be displayed."
Else
MsgBox "The AutoCorrect Options button cannot be displayed."
End If
End Sub

AutoCorrect.Parent Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax
expression .Parent

expression A variable that represents an AutoCorrect object.

AutoCorrect.ReplacementList Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the array of AutoCorrect replacements.

Syntax

expression .ReplacementList(Index)

expression A variable that represents an AutoCorrect object.

Parameters
Data
Name Required/Optional Description
Type

The row index of the array of AutoCorrect replacements to be returned. The


row is returned as a one-dimensional array with two elements: The first
Index Optional Variant
element is the text in column 1, and the second element is the text in column
2.

Remarks
If Index is not specified, this method returns a two-dimensional array. Each row in the array contains one
replacement, as shown in the following table.

Column Contents

1 The text to be replaced

2 The replacement text

Use the AddReplacement method to add an entry to the replacement list.

Example

This example searches the replacement list for "Temperature" and displays the replacement entry if it exists.

VBA

repl = Application.AutoCorrect.ReplacementList
For x = 1 To UBound(repl)
If repl(x, 1) = "Temperature" Then MsgBox repl(x, 2)
Next

AutoCorrect.ReplaceText Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if text in the list of AutoCorrect replacements is replaced automatically. Read/write Boolean.

Syntax
expression .ReplaceText

expression A variable that represents an AutoCorrect object.

Example
This example turns off automatic text replacement.

VBA
With Application.AutoCorrect
.CapitalizeNamesOfDays = True
.ReplaceText = False
End With

utoCorrect.TwoInitialCapitals Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if words that begin with two capital letters are corrected automatically. Read/write Boolean.

Syntax
expression .TwoInitialCapitals

expression A variable that represents an AutoCorrect object.

Example
This example sets Microsoft Excel to correct words that begin with two capital letters.

VBA
With Application.AutoCorrect
.TwoInitialCapitals = True
.ReplaceText = True
End With
utoFilter Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents autofiltering for the specified worksheet.

Note

When using AutoFilter with dates, the format should be consistent with English date separators ("/") instead of
local settings ("."). A valid date would be "2/2/2007", whereas "2.2.2007" is invalid.

Note

Working with objects (e g Interior Object) requires adding a reference to an object. You will find more
information about assigning an Object reference to a variable or property in the Set Statement.

Example
Use the AutoFilter property to return the AutoFilter object. Use the Filters property to return a collection of
individual column filters. Use the Range property to return the Range object that represents the entire filtered
range. The following example stores the address and filtering criteria for the current filtering and then applies new
filters.

VBA

Dim w As Worksheet
Dim filterArray()
Dim currentFiltRange As String

Sub ChangeFilters()

Set w = Worksheets("Crew")
With w.AutoFilter
currentFiltRange = .Range.Address
With .Filters
ReDim filterArray(1 To .Count, 1 To 3)
For f = 1 To .Count
With .Item(f)
If .On Then
filterArray(f, 1) = .Criteria1
If .Operator Then
filterArray(f, 2) = .Operator
filterArray(f, 3) = .Criteria2
End If
End If
End With
Next
End With
End With

w.AutoFilterMode = False
w.Range("A1").AutoFilter field:=1, Criteria1:="S"

End Sub
To create an AutoFilter object for a worksheet, you must turn autofiltering on for a range on the worksheet either
manually or using the AutoFilter method of the Range object. The following example uses the values stored in
module-level variables in the previous example to restore the original autofiltering to the Crew worksheet.

VBA

Sub RestoreFilters()
Set w = Worksheets("Crew")
w.AutoFilterMode = False
For col = 1 To UBound(filterArray(), 1)
If Not IsEmpty(filterArray(col, 1)) Then
If filterArray(col, 2) Then
w.Range(currentFiltRange).AutoFilter field:=col, _
Criteria1:=filterArray(col, 1), _
Operator:=filterArray(col, 2), _
Criteria2:=filterArray(col, 3)
Else
w.Range(currentFiltRange).AutoFilter field:=col, _
Criteria1:=filterArray(col, 1)
End If
End If
Next
End Sub

Note

When using AutoFilter with dates, the format should be consistent with English date separators ("/") instead of
local settings ("."). A valid date would be "2/2/2007", whereas "2.2.2007" is invalid.
Methods

Name

ApplyFilter

ShowAllData

Properties

Name

Application

Creator

FilterMode

Filters

Parent

Range

Sort

AutoFilter.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents an AutoFilter object.

Example

This example displays a message about the application that created myObject.

VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
utoFilter.ApplyFilter Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Applies the specified Autofilter object.

Syntax

expression .ApplyFilter

expression A variable that represents an AutoFilter object.

AutoFilter.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents an AutoFilter object.

AutoFilter.FilterMode Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns True if the worksheet is in the AutoFilter filter mode. Read-only Boolean.

Syntax

expression .FilterMode

expression A variable that represents an AutoFilter object.

utoFilter.Filters Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Filters collection that represents all the filters in an autofiltered range. Read-only.

Syntax

expression .Filters

expression A variable that represents an AutoFilter object.

Example

The following example sets a variable to the value of the Criteria1 property of the filter for the first column in the
filtered range on the Crew worksheet.

VBA

With Worksheets("Crew")
If .AutoFilterMode Then
With .AutoFilter.Filters(1)
If .On Then c1 = .Criteria1
End With
End If
End With
AutoFilter.Parent Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents an AutoFilter object.

utoFilter.Range Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Range object that represents the range to which the specified AutoFilter applies.

Syntax

expression .Range

expression A variable that represents an AutoFilter object.

Example

The following example stores in a variable the address for the AutoFilter applied to the Crew worksheet.

VBA

rAddress = Worksheets("Crew").AutoFilter.Range.Address
This example scrolls through the workbook window until the hyperlink range is in the upper-left corner of the
active window.

VBA

Workbooks(1).Activate
Set hr = ActiveSheet.Hyperlinks(1).Range
ActiveWindow.ScrollRow = hr.Row
ActiveWindow.ScrollColumn = hr.Column
AutoFilter.ShowAllData Method (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Displays all the data returned by the AutoFilter object.

Syntax

expression .ShowAllData

expression A variable that represents an AutoFilter object.

See also

utoFilter.Sort Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Gets the sort column or columns, and sort order for the AutoFilter collection.

Syntax

expression .Sort

expression A variable that represents an AutoFilter object.

Axes Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of all the Axis objects in the specified chart.

Remarks

Use the Axes method to return the Axes collection.


Use Axes(type, group), where type is the axis type and group is the axis group, to return a single Axis object. Type
can be one of the following XlAxisType constants: xlCategory, xlSeries, or xlValue. Group can be one of the
following XlAxisGroup constants: xlPrimary or xlSecondary. For more information, see the Axes method.

Example

The following example displays the number of axes on embedded chart one on worksheet one.

VBA

With Worksheets(1).ChartObjects(1).Chart
MsgBox.Axes.Count
End With
The following example sets the category axis title text on the chart sheet named "Chart1."

VBA

With Charts("chart1").Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
Methods

Name

Item

Properties

Name

Application

Count

Creator

Parent

Axes.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax

expression .Application

expression A variable that represents an Axes object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Axes.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax

expression .Count

expression A variable that represents an Axes object.

Axes.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator
expression A variable that represents an Axes object.

Axes.Item Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a single Axis object from an Axes collection.

Syntax

expression .Item(Type, AxisGroup)

expression A variable that represents an Axes object.

Parameters
Name Required/Optional Data Type Description

Type Required XlAxisType The axis type.

AxisGroup Optional XlAxisGroup The axis.

Return Value
Axis

Example

This example sets the title text for the category axis on Chart1.

VBA

With Charts("chart1").Axes.Item(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
XlAxisType Enumeration (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Specifies the axis type.

Name Value Description

xlCategory 1 Axis displays categories.

xlSeriesAxis 3 Axis displays data series.

xlValue 2 Axis displays values.

XlAxisGroup Enumeration (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Specifies the type of axis group.

Name Value Description

xlPrimary 1 Primary axis group.

xlSecondary 2 Secondary axis group.

xis Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents a single axis in a chart.

Remarks

The Axis object is a member of the Axes collection.

Use Axes(type, group) where type is the axis type and group is the axis group to return a single Axis object. Type
can be one of the following XlAxisType constants: xlCategory, xlSeries, or xlValue. Group can be one of the
following XlAxisGroup constants: xlPrimary or xlSecondary. For more information, see the Axes method.

Example
The following example sets the category axis title text on the chart sheet named "Chart1."

VBA

With Charts("chart1").Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "1994"
End With
Methods

Name

Delete

Select

Properties

Name

Application

AxisBetweenCategories

AxisGroup

AxisTitle

BaseUnit

BaseUnitIsAuto

Border

CategoryNames

CategoryType

Creator

Crosses

CrossesAt

DisplayUnit

DisplayUnitCustom

DisplayUnitLabel

Format

HasDisplayUnitLabel

HasMajorGridlines
HasMinorGridlines

HasTitle

Height

Left

LogBase

MajorGridlines

MajorTickMark

MajorUnit

MajorUnitIsAuto

MajorUnitScale

MaximumScale

MaximumScaleIsAuto

MinimumScale

MinimumScaleIsAuto

MinorGridlines

MinorTickMark

MinorUnit

MinorUnitIsAuto

MinorUnitScale

Parent

ReversePlotOrder

ScaleType

TickLabelPosition

TickLabels

TickLabelSpacing

TickLabelSpacingIsAuto

TickMarkSpacing
Top

Type

Width

Border Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents the border of an object.

Remarks

Most bordered objects (all except for the Range and Style objects) have a border thats treated as a single entity,
regardless of how many sides it has. The entire border must be returned as a unit. Use the Border property, such as
from a TrendLine object, to return the Border object for this kind of object.

Example

The following example changes the type and line style of a trend line on the active chart.

VBA

With ActiveChart.SeriesCollection(1).Trendlines(1)
.Type = xlLinear
.Border.LineStyle = xlDash
End With
Range and Style objects have four discrete borders left, right, top, and bottom which can be returned
individually or as a group. Use the Borders property to return the Borders collection, which contains all four
borders and treats the borders as a unit. The following example adds a double border to cell A1 on worksheet one.

VBA

Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders(index), where index identifies the border, to return a single Border object. The following example
sets the color of the bottom border of cells A1:G1.

VBA

Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
Index can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom,
xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.

Properties

Name

Application
Color

ColorIndex

Creator

LineStyle

Parent

ThemeColor

TintAndShade

Weight

Border.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a Border object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
See also

Border.Color Property (Excel)


Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the primary color of the object, as shown in the table in the remarks section. Use the RGB function
to create a color value. Read/write Variant.

Syntax

expression .Color

expression An expression that returns a Border object.

Remarks

Object Color

Border The color of the border.

Borders The color of all four borders of a range. If they're not all the same color, Color returns 0 (zero).

Font The color of the font.

Interior The cell shading color or the drawing object fill color.

Tab The color of the tab.

Example

This example sets the color of the tick-mark labels on the value axis in Chart1.

VBA

Charts("Chart1").Axes(xlValue).TickLabels.Font.Color = _
RGB(0, 255, 0)

Border.ColorIndex Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.
Returns or sets a Variant value that represents the color of the border.

Syntax
expression .ColorIndex

expression A variable that represents a Border object.

Remarks
The color is specified as an index value into the current color palette, or as one of the following XlColorIndex
constants:

xlColorIndexAutomatic

xlColorIndexNone

Example
This example sets the color of the major gridlines for the value axis in Chart1.

VBA
With Charts("Chart1").Axes(xlValue)
If .HasMajorGridlines Then
.MajorGridlines.Border.ColorIndex = 5 'set color to blue
End If
End With
Border.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a Border object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.
Border.LineStyle Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the line style for the border. Read/write XlLineStyle, xlGray25, xlGray50, xlGray75, or
xlAutomatic.

Syntax

expression .LineStyle

expression A variable that represents a Border object.

Remarks

xlDouble and xlSlantDashDot do not apply to charts.

Example

This example puts a border around the chart area and the plot area of Chart1.

VBA

With Charts("Chart1")
.ChartArea.Border.LineStyle = xlDashDot
With .PlotArea.Border
.LineStyle = xlDashDotDot
.Weight = xlThick
End With
End With
order.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent
expression A variable that represents a Border object.

Border.ThemeColor Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the theme color in the applied color scheme that is associated with the specified object. Read/write
Variant.

Syntax

expression .ThemeColor

expression A variable that represents a Border object.

Remarks

Attempting to access a theme color for an object whose color is not currently themed will result in an invalid
request run-time error.

Border.TintAndShade Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Single that lightens or darkens a color.

Syntax

expression .TintAndShade

expression A variable that represents a Border object.

Remarks

You can enter a number from -1 (darkest) to 1 (lightest) for the TintAndShade property. Zero (0) is neutral.

Attempting to set this property to a value less than -1 or more than 1 results in a run-time error: "The specified
value is out of range." This property works for both theme colors and nontheme colors.
order.Weight Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a XlBorderWeight value that represents the weight of the border.

Syntax

expression .Weight

expression A variable that represents a Border object.

Example

This example sets the border weight for oval one on Sheet1.

VBA

Worksheets("Sheet1").Ovals(1).Border.Weight = xlMedium
Borders Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of four Border objects that represent the four borders of a Range or Style object.

Remarks

Use the Borders property to return the Borders collection, which contains all four borders.

You can set border properties for an individual border only with Range and Style objects. Other bordered objects,
such as error bars and series lines, have a border thats treated as a single entity, regardless of how many sides it
has. For these objects, you must return and set properties for the entire border as a unit. For more information, see
the Border object.

Example

The following example adds a double border to cell A1 on worksheet one.


VBA

Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders(index), where index identifies the border, to return a single Border object. The following example
sets the color of the bottom border of cells A1:G1 to red.

VBA

Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
Index can be one of the following xlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom,
xlEdgeLeft, xlEdgeRight, or xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.

Properties

Name

Application

Color

ColorIndex

Count

Creator

Item

LineStyle

Parent

ThemeColor

TintAndShade

Value

Weight

Borders.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a Borders object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Borders.Color Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the primary color of the object, as shown in the table in the remarks section. Use the RGB function
to create a color value. Read/write Variant.

Syntax

expression .Color

expression An expression that returns a Borders object.

Remarks

Object Color

Border The color of the border.

Borders The color of all four borders of a range. If they're not all the same color, Color returns 0 (zero).

Font The color of the font.

Interior The cell shading color or the drawing object fill color.

Tab The color of the tab.


Example

This example sets the color of the tick-mark labels on the value axis in Chart1.

VBA

Charts("Chart1").Axes(xlValue).TickLabels.Font.Color = _
RGB(0, 255, 0)

Borders.ColorIndex Property (Excel)


Office 2013 and later
Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the color of all four borders.

Syntax
expression .ColorIndex

expression A variable that represents a Borders object.

Remarks
This property returns Null if all four borders aren't the same color.

The color is specified as an index value into the current color palette, or as one of the following XlColorIndex
constants:

xlColorIndexAutomatic

xlColorIndexNone

Borders.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.
Syntax

expression .Count

expression A variable that represents a Borders object.

Borders.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a Borders object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

Borders.Item Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Border object that represents one of the borders of either a range of cells or a style.

Syntax

expression .Item(Index)

expression A variable that represents a Borders object.


Parameters
Name Required/Optional Data Type Description

Index Required XlBordersIndex One of the constants of XlBordersIndex.

Remarks

XlBordersIndex can be one of these XlBordersIndex constants.

xlDiagonalDown

xlDiagonalUp

xlEdgeBottom

xlEdgeLeft

xlEdgeRight

xlEdgeTop

xlInsideHorizontal

xlInsideVertical

Example

This following example sets the color of the bottom border of cells A1:G1.

VBA

Worksheets("Sheet1").Range("a1:g1"). _
Borders.Item(xlEdgeBottom).Color = RGB(255, 0, 0)
Borders.LineStyle Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the line style for the border. Read/write XlLineStyle, xlGray25, xlGray50, xlGray75, or
xlAutomatic.

Syntax

expression .LineStyle

expression A variable that represents a Borders object.

Example
This example puts a border around the chart area and the plot area of Chart1.

VBA

With Charts("Chart1")
.ChartArea.Border.LineStyle = xlDashDot
With .PlotArea.Border
.LineStyle = xlDashDotDot
.Weight = xlThick
End With
End With
Borders.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a Borders object.

Borders.ThemeColor Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the theme color in the applied color scheme that is associated with the specified object. Read/write
Variant.

Syntax

expression .ThemeColor

expression A variable that represents a Borders object.

Borders.TintAndShade Property (Excel)

Office 2013 and later


Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Single that lightens or darkens a color.

Syntax

expression .TintAndShade

expression A variable that represents a Borders object.

Remarks

You can enter a number from -1 (darkest) to 1 (lightest) for the TintAndShade property. Zero (0) is neutral.

Attempting to set this property to a value less than -1 or more than 1 results in a run-time error: "The specified
value is out of range." This property works for both theme colors and nontheme colors.

Borders.Value Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Synonym for Borders.LineStyle.

Syntax

expression .Value

expression A variable that represents a Borders object.

Borders.Weight Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a XlBorderWeight value that represents the weight of the border.

Syntax

expression .Weight

expression A variable that represents a Borders object.

CalculatedFields Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of PivotField objects that represents all the calculated fields in the specified PivotTable report.

Remarks

A report that contains Revenue and Expense fields could have a calculated field named Profit defined as the
amount in the Revenue field minus the amount in the Expense field.

For OLAP data sources, you cannot set this collection, and it always returns Nothing.

Use the CalculatedFields method to return the CalculatedFields collection .

Use CalculatedFields(index), where index is specified fields name or index number, to return a single PivotField
object from the CalculatedFields collection.

Example

The following example deletes the calculated fields from the PivotTable report named Pivot1

VBA

For Each fld in _


Worksheets(1).PivotTables("Pivot1").CalculatedFields
fld.Delete
Next
CalculatedFields.Add Method (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Creates a new calculated field. Returns a PivotField object.

Syntax

expression .Add(Name, Formula, UseStandardFormula)

expression A variable that represents a CalculatedFields object.

Parameters
Data
Name Required/Optional Description
Type

Name Required String The name of the field.

Formula Required String The formula for the field.

False (default) for upward compatibility. True for strings


contained in any arguments that are field names, will be
UseStandardFormula Optional Variant
interpreted as having been formatted in standard U.S. English
instead of local settings.

Return Value
A PivotField that represents the new calculated field.

Example

This example adds a calculated field to the first PivotTable report on worksheet one.

VBA

Worksheets(1).PivotTables(1).CalculatedFields.Add "PxS", _
"= Product * Sales"
CalculatedFields.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a CalculatedFields object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CalculatedFields.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax

expression .Count

expression A variable that represents a CalculatedFields object.

CalculatedFields.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.
Syntax

expression .Creator

expression A variable that represents a CalculatedFields object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

CalculatedFields.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CalculatedFields object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

CalculatedFields.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.


Syntax

expression .Parent

expression A variable that represents a CalculatedFields object.

CalculatedItems Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of PivotItem objects that represent all the calculated items in the specified PivotTable report.

Remarks

A PivotTable report that contains January, February, and March items could have a calculated item named
FirstQuarter defined as the sum of the amounts in January, February, and March.

Use the CalculatedItems method to return the CalculatedItems collection.

Use CalculatedFields(index), where index is the name or index number of the field, to return a single PivotField
object from the CalculatedFields collection.

Example

The following example creates a list of the calculated items in the first PivotTable report on worksheet one, along
with their formulas.

VBA

Set pt = Worksheets(1).PivotTables(1)
For Each ci In pt.PivotFields("Sales").CalculatedItems
r = r + 1
With Worksheets(2)
.Cells(r, 1).Value = ci.Name
.Cells(r, 2).Value = ci.Formula
End With
Next
CalculatedItems.Add Method (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Creates a new calculated item. Returns a PivotItem object.

Syntax

expression .Add(Name, Formula, UseStandardFormula)

expression A variable that represents a CalculatedItems object.

Parameters
Data
Name Required/Optional Description
Type

Name Required String The name of the item.

Formula Required String The formula for the item.

False (default) for upward compatibility. True for strings


contained in any arguments that are item names, will be
UseStandardFormula Optional Variant
interpreted as having been formatted in standard U.S. English
instead of local settings.

Return Value
A PivotItem object that represents the new calculated item.

CalculatedItems.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a CalculatedItems object.

Example
This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CalculatedItems.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax

expression .Count

expression A variable that represents a CalculatedItems object.

CalculatedItems.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CalculatedItems object.

CalculatedItems.Item Method (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a single object from a collection.

Syntax

expression .Item(Index)

expression A variable that represents a CalculatedItems object.

Parameters
Name Required/Optional Data Type Description

Index Required Variant The name or index number for the object.

Return Value
A PivotItem object contained by the collection.

Remarks

The text name of the object is the value of the Name and Value properties.

Example

This example hides calculated item one.

VBA

Worksheets(1).PivotTables(1).PivotFields("year") _
.CalculatedItems.Item(1).Visible = False
CalculatedItems.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a CalculatedItems object.


CalculatedMember Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents the calculated fields, calculated items, and named sets for PivotTables with Online Analytical
Processing (OLAP) data sources.

Remarks

Use the Add method or the Item property of the CalculatedMembers collection to return a CalculatedMember
object.

With a CalculatedMember object you can check the validity of a calculated field or item in a PivotTable using the
IsValid property.

Note

The IsValid property will return True if the PivotTable is not currently connected to the data source. Use the
MakeConnection method before testing the IsValid property.

Example

The following example notifies the user if the calculated member is valid or not. This example assumes a
PivotTable exists on the active worksheet that contains either a valid or invalid calculated member.

VBA

Sub CheckValidity()

Dim pvtTable As PivotTable


Dim pvtCache As PivotCache

Set pvtTable = ActiveSheet.PivotTables(1)


Set pvtCache = Application.ActiveWorkbook.PivotCaches.Item(1)

' Handle run-time error if external source is not an OLEDB data source.
On Error GoTo Not_OLEDB

' Check connection setting and make connection if necessary.


If pvtCache.IsConnected = False Then
pvtCache.MakeConnection
End If

' Check if calculated member is valid.


If pvtTable.CalculatedMembers.Item(1).IsValid = True Then
MsgBox "The calculated member is valid."
Else
MsgBox "The calculated member is not valid."
End If

End Sub
CalculatedMember Object
Application Property

Creator Property

Delete Method

DisplayFolder Property

Dynamic Property

FlattenHierarchies Property

Formula Property

HierarchizeDistinct Property

IsValid Property

MeasureGroup Property

Name Property

NumberFormat Property

Parent Property

ParentHierarchy Property

ParentMember Property

SolveOrder Property

SourceName Property

Type Property

CalculatedMember.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a CalculatedMember object.


Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CalculatedMember.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CalculatedMember object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XCEL.

CalculatedMember.Delete Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Deletes the object.

Syntax
expression .Delete

expression A variable that represents a CalculatedMember object.

CalculatedMember.DisplayFolder Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the display folder name for a named set. Read-only

Syntax

expression .DisplayFolder

expression A variable that returns a CalculatedMember object.

Return Value
String

Remarks

The value of this property corresponds to the optional value that can be entered in the Display folder text box of
the New/Modify Set dialog box when a named set is created or edited. To create a new named set from data in a
PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the PivotTable Tools
Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then click Create Set
using MDX. This will display the New Set dialog box, which contains the Display folder text box. Similarly, if
you select an existing named set in the Set Manager dialog box, and then click Edit, the Modify Set dialog box is
displayed.

This property along with the Dynamic and HierarchizeDistinct properties can only be read for named sets (which
are represented by CalculatedMember objects where the Type property equals xlCalculatedSet). These
properties for cannot be read for calculated members or measures (which are represented by CalculatedMember
objects where the Type property equals xlCalculatedMember). If you attempt to read these properties for
calculated members or measures, a run-time error is raised.

alculatedMember.Dynamic Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns whether the specified named set is recalculated with every update. Read-only

Syntax

expression .Dynamic

expression A variable that returns a CalculatedMember object.

Return Value
Boolean

Remarks

True if the named set is recalculated with every update; otherwise False.

The value of this property corresponds to the setting of the Recalculate set with every update check box in the
New/Modify Set dialog box that is available when a named set is created or edited. To create a new named set
from data in a PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the
PivotTable Tools Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then
click Create Set using MDX. This will display the New Set dialog box, which contains the Recalculate set with
every update check box. Similarly, if you select an existing named set in the Set Manager dialog box, and then
click Edit, the Modify Set dialog box is displayed.

This property along with the DisplayFolder and HierarchizeDistinct properties can only be read for named sets
(which are represented by CalculatedMember objects where the Type property equals xlCalculatedSet). These
properties for cannot be read for calculated members or measures (which are represented by CalculatedMember
objects where the Type property equals xlCalculatedMember). If you attempt to read these properties for
calculated members or measures, a run-time error is raised.

CalculatedMember.FlattenHierarchies Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets whether items from all levels of the hierarchy of the specified named set are displayed in the same
field of a PivotTable report based on an OLAP cube. Boolean Read/write

Syntax

expression .FlattenHierarchies

expression A variable that represents a CalculatedMember object.


Return Value
Boolean

Remarks

True if items from all levels of the hierarchy of the named set are displayed in the same field; otherwise False.

The value of this property corresponds to the setting of the Display items from different levels in separate fields
check box in the New/Modify Set dialog box when a named set is created or edited. To create a new named set
from data in a PivotTable based on an OLAP data source, click the PivotTable, click Field, Items, & Sets on the
PivotTable Tools Options tab on the ribbon, click Manage Sets, click New in the Set Manager dialog box, and then
click Create Set using MDX. This will display the New Set dialog box, which contains the Display items from
different levels in separate fields check box. Similarly, if you select an existing named set in the Set Manager
dialog box, and then click Edit, the Modify Set dialog box is displayed.

CalculatedMember.Formula Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a String value that represents the member's formula in multidimensional expressions (MDX) syntax.

Syntax

expression .Formula

expression A variable that represents a CalculatedMember object.

Remarks

If the cell contains a constant, this property returns the constant. If the cell is empty, this property returns an empty
string. If the cell contains a formula, the Formula property returns the formula as a string in the same format that
would be displayed in the formula bar (including the equal sign).

If you set the value or formula of a cell to a date, Microsoft Excel checks to see whether that cell is already
formatted with one of the date or time number formats. If not, Microsoft Excel changes the number format to the
default short date number format.

If the range is a one or two-dimensional range, you can set the formula to a Visual Basic array of the same
dimensions. Similarly, you can put the formula into a Visual Basic array.

Setting the formula for a multiple-cell range fills all cells in the range with the formula.

CalculatedMember.HierarchizeDistinct Property (Excel)

Office 2013 and later


Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets whether to order and remove duplicates when displaying the hierarchy of the specified named set
in a PivotTable report based on an OLAP cube. Read/write

Syntax

expression .HierarchizeDistinct

expression A variable that returns a CalculatedMember object.

Return Value
Boolean

CalculatedMember.IsValid Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Boolean that indicates whether the specified calculated member has been successfully instantiated with
the OLAP provider during the current session.

Syntax

expression .IsValid

expression A variable that represents a CalculatedMember object.

Remarks

This property returns True even if the PivotTable is not connected to its data source. Make sure that the PivotTable
is connected before querying the value of the IsValid property.

CalculatedMember.MeasureGroup Property (Excel)

Office 2013 and later


Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the associated measure group. String Read-only

Syntax

expression .MeasureGroup

expression A variable that represents a CalculatedMember object.

Property value

STRING

CalculatedMember.Name Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a String value that represents the name of the object.

Syntax

expression .Name

expression A variable that represents a CalculatedMember object.

CalculatedMember.NumberFormat Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a XlCalcMemNumberFormatType value that represents the number format of the calculated member.
The default value is xlNumberFormatTypeDefault. Read-only.

Syntax

expression .NumberFormat

expression A variable that represents a CalculatedMember object.

Property value
XLCALCMEMNUMBERFORMATTYPE

CalculatedMember.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a CalculatedMember object.

CalculatedMember.ParentHierarchy Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the name of the current parent hierarchy from the hierarchies that are available on the cube. String Read-
only

Syntax

expression .ParentHierarchy

expression A variable that represents a CalculatedMember object.

CalculatedMember.ParentMember Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the name of the parent member for the parent hierarchy. String Read-only

Syntax

expression .ParentMember

expression A variable that represents a CalculatedMember object


CalculatedMember.SolveOrder Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long specifying the value of the calculated member's solve order MDX (Mulitdimensional Expression)
argument. The default value is zero. Read-only.

Syntax

expression .SolveOrder

expression A variable that represents a CalculatedMember object.

Example

This example determines the solve order for a calculated member and notifies the user. The example assumes a
PivotTable exists on the active worksheet.

VBA

Sub CheckSolveOrder()

Dim pvtTable As PivotTable

Set pvtTable = ActiveSheet.PivotTables(1)

' Determine solve order and notify user.


If pvtTable.CalculatedMembers.Item(1).SolveOrder = 0 Then
MsgBox "The solve order is set to the default value."
Else
MsgBox "The solve order is not set to the default value."
End If

End Sub
CalculatedMember.SourceName Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a String value that represents the specified objects name as it appears in the original source data for the
specified PivotTable report.
Syntax

expression .SourceName

expression A variable that represents a CalculatedMember object.

CalculatedMember.Type Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a XlCalculatedMemberType value that represents the calculated member type.

Syntax

expression .Type

expression A variable that represents a CalculatedMember object.

alculatedMembers Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

A collection of all the CalculatedMember objects on the specified PivotTable.

Remarks

Each CalculatedMember object represents a calculated member or calculated measure.

Use the CalculatedMembers property of the PivotTable object to return a CalculatedMembers collection.

There are three supported types of calculated members: Named Sets, Calculated Measures, and Calculated
Members. Object model support has been available for all three of these types since Excel 2010. User interface
support was made available for Named Sets in Excel 2010. In Excel 2013, the OLAP Calculated Members and
Calculated Measures feature was created to build a user interface for the calculated members and measures object
model.
Named Sets are used exactly the same as in Excel 2010. Named Sets should continue to use the method
CalculatedMembers.CalculatedMembers.Add Method (Excel) and the type XlCalculatedMemberType
Enumeration (Excel).

Calculated Members have the following changes for Excel 2013:

They now use the method called CalculatedMembers.CalculatedMembers.AddCalculatedMember Method


(Excel).

They support the property CalculatedMember.ParentHierarchy Property (Excel).

They support the property CalculatedMember.ParentMember Property (Excel).

They support the property CalculatedMember.NumberFormat Property (Excel).

Calculated Measures have the following changes for Excel 2013:

They now use the method called CalculatedMembers.CalculatedMembers.AddCalculatedMember Method


(Excel).

They now use the type XlCalculatedMemberType Enumeration (Excel).

They support the property CalculatedMember.DisplayFolder Property (Excel).

They support the property CalculatedMember.NumberFormat Property (Excel).

Example

The following example adds a set to a PivotTable, assuming a PivotTable from the FoodMart SQL database exists
on the active worksheet.

VBA

Sub UseCalculatedMember()
Dim pvtTable As PivotTable
Set pvtTable = ActiveSheet.PivotTables(1)
pvtTable.CalculatedMembers.Add Name:="[Beef]", _
Formula:="'{[Product].[All Products].Children}'", _
Type:=xlCalculatedSet

End Sub
Note

For the Add method in the previous example, the Formula argument must have a valid MDX syntax statement.
The Name argument has to be acceptable to the Online Analytical Processing (OLAP) provider and the Type
argument has to be defined.

Add Method

AddCalculatedMember Method

Application Property

Count Property

Creator Property
Item Property

Parent Property

alculatedMembers.Add Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Adds a calculated field or calculated item to a PivotTable. Returns a CalculatedMember object.

Syntax

expression .Add(Name, Formula, SolveOrder, Type)

expression A variable that represents a CalculatedMembers object.

Parameters
Data
Name Required/Optional Description
Type

Name Required String The name of the calculated member.

Formula Required String The formula of the calculated member.

SolveOrder Optional Variant The solve order for the calculated member.

Type Optional Variant The type of calculated member.

Specifies if the calculated member is recalculated with every


Dynamic Optional Boolean
update.

DisplayFolder Optional String The name of the display folder for the calculated member.

Specifies whether to order and remove duplicates when


HierarchizeDistinct Optional Boolean displaying the hierarchy of the calculated member in a
PivotTable report based on an OLAP cube.

Return Value
A CalculatedMember object that represents the new calculated field or calculated item.

Remarks

The Formula argument must contain a valid MDX (Multidimensional Expression) syntax statement. The Name
argument has to be acceptable to the Online Analytical Processing (OLAP) provider and the Type argument has to
be defined.
If you set the Type argument of this method to xlCalculatedSet, then you must call the AddSet method to make
the new field set visible in the PivotTable.

Example

The following example adds a set to a PivotTable.

Note

Connection to the cube and existing pivot table is necessary for the sample to run.

VBA

Sub UseAddSet()

Dim pvtOne As PivotTable


Dim strAdd As String
Dim strFormula As String
Dim cbfOne As CubeField

Set pvtOne = ActiveSheet.PivotTables(1)

strAdd = "[MySet]"
strFormula = "'{[Product].[All Products].[Food].children}'"

' Establish connection with data source if necessary.


If Not pvtOne.PivotCache.IsConnected Then pvtOne.PivotCache.MakeConnection

' Add a calculated member titled "[MySet]"


pvtOne.CalculatedMembers.Add Name:=strAdd, _
Formula:=strFormula, Type:=xlCalculatedSet

' Add a set to the CubeField object.


Set cbfOne = pvtOne.CubeFields.AddSet(Name:="[MySet]", _
Caption:="My Set")

End Sub
CalculatedMembers.AddCalculatedMember Method (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Adds a calculated field or calculated item to a PivotTable.

Syntax

expression
.AddCalculatedMember(Name,Formula,SolveOrder,Type,DisplayFolder,MeasureGroup,ParentHierarchy,ParentM
ember,NumberFormat)

expression A variable that represents a CalculatedMembers object.

Parameters
Name Required/Optional Data type Description

Name Required STRING The name of the calculated member.

Formula Required VARIANT The formula of the calculated member.


SolveOrder Optional VARIANT The solve order for the calculated member.

Type Optional VARIANT The type of calculated member.

DisplayFolder Optional VARIANT A folder that exists to display calculated measures.

MeasureGroup Optional VARIANT The group to which the calculated belongs.

ParentHierarchy Optional VARIANT The parent path of the ParentMember.

ParentMember Optional VARIANT The parent of the calculated member.

NumberFormat Optional VARIANT The format of numbers used for calculated members.

Return value
CALCULATEDMEMBER

Remarks
The Formula argument must have a valid MDX (multidimensional expression) syntax statement. The Name
argument has to be acceptable to the Online Analytical Processing (OLAP) provider.

DisplayFolder: Display folders are only valid for calculated measures. They are not valid for calculated
members. The string can have semicolons ; in it. Semicolons designate multiple display folders. For
example, if you use the string my folder1;myfolder2 then the calculated measure will show in two display
folders one named myfolder1 the other named ?myfolder2?. The string can have backslashes \. This
designates a hierarchical path for the display folder. For example, if you use the string welcome\to\seattle
there will be a display folder called welcome that contains a display folder called to which contains a
display folder called seattle. Display folders are virtual folders.? They do not really exist in the same sense
that we think of system folders. They only exist for purposes of displaying the calculated measures.

NumberFormat: The number formats can only be set by macros. There is no user interface for setting
them. This is the only property that cannot be set via the user interface. The type is always
xlNumberFormatTypeDefault when a calculated member is created via the user interface. The number
formats are only valid for calculated members. They are not valid for calculated measures.

ParentHierarchy: The parent hierarchy can be any valid MDX hierarchy. Parent hierarchies are only valid
for calculated members. They are not valid for calculated measures. If a parent member is chosen that is in
a different parent hierarchy, the parent hierarchy will be automatically changed to match the parent
hierarchy of the parent member. For example, assume the following macro for a calculated member:

T-SQL

OLEDBConnection.CalculatedMembers.AddCalculatedMember Name:="[UK+US]", _
Formula:= _
"[Customer].[Customer Geography].[Country].&[United Kingdom] + [Customer].
[Customer Geography].[Country].&[United States] " _
, Type:=xlCalculatedMember, SolveOrder:=0, ParentHierarchy:= _
"[Account].[Accounts]", ParentMember:= _
"[Customer].[Customer Geography].[Australia]", NumberFormat:= _
xlNumberFormatTypePercent
In this case you have specified that the parent member is from the [Customer].[Customer Geography]
hierarchy yet you have given the parent hierarchy as [Account].[Accounts]. When the member is created, it
will use the parent hierarchy of the parent member which is [Customer].[Customer Geography] and when
you look in the Manage Calculations dialog in the UI, it will show [Customer].[Customer Geography] as
the parent hierarchy rather than the one specified in the macro, i.e. [Account].[Accounts].

Example
The following code sample adds a calculated measure to a PivotTable.

Note

In both of these samples, the PivotTable must be refreshed after creating the calculation in order to view it in the
user interface.

VBA

Sub AddCalculatedMeasure()

Dim pvt As PivotTable


Dim strName As String
Dim strFormula As String
Dim strDisplayFolder As String
Dim strMeasureGroup As String

Set pvt = Sheet1.PivotTables("PivotTable1")


strName = "[Measures].[Internet Sales Amount 25 %]"
strFormula = "[Measures].[Internet Sales Amount]*1.25"
strDisplayFolder = "My Folder\Percent Calculations"
strMeasureGroup = "Internet Sales"

pvt.CalculatedMembers. AddCalculatedMember Name:=strName, Formula:=strFormula,


Type:=xlCalculatedMeasure, DisplayFolder:=strDisplayFolder, MeasureGroup:=strMeasureGroup,
NumberFormat:=xlNumberFormatTypePercent

End Sub
The following code sample adds a calculated member to a PivotTable.

VBA

Sub AddCalculatedMember()

Dim pvt As PivotTable


Dim strName As String
Dim strFormula As String
Dim strParentHierarchy As String
Dim strParentMember As String

Set pvt = Sheet1.PivotTables("PivotTable1")


strName = "[Customer].[Customer Geography].[All Customers].[North America]"
strFormula = "[Customer].[Customer Geography].[Country].&[United States] + [Customer].
[Customer Geography].[Country].&[Canada]"
strParentHierarchy = "[Customer].[Customer Geography]"
strParentMember = "[Customer].[Customer Geography].[All Customers]"

pvt.CalculatedMembers. AddCalculatedMember Name:=strName, Formula:=strFormula,


Type:=xlCalculatedMember, ParentHierarchy:=strParentHierarchy,
ParentMember:=strParentMember, SolveOrder:=0, NumberFormat:=xlNumberFormatTypeDefault

End Sub
CalculatedMembers.Application Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a CalculatedMembers object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CalculatedMembers.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax

expression .Count

expression A variable that represents a CalculatedMembers object.

alculatedMembers.Creator Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CalculatedMembers object.

Remarks

If the object was created in Microsoft Excel, this property returns the string XCEL, which is equivalent to the
hexadecimal number 5843454C. The Creator property is designed to be used in Microsoft Excel for the
Macintosh, where each application has a four-character creator code. For example, Microsoft Excel has the creator
code XC

CalculatedMembers.Item Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a single object from a collection.

Syntax

expression .Item(Index)

expression A variable that represents a CalculatedMembers object.

Parameters
Name Required/Optional Data Type Description

Index Required Variant The name or index number of the object.

Example

The following example notifies the user if the calculated member is valid or not. This example assumes a
PivotTable exists on the active worksheet that contains either a valid or invalid calculated member.

VBA
Sub CheckValidity()

Dim pvtTable As PivotTable


Dim pvtCache As PivotCache

Set pvtTable = ActiveSheet.PivotTables(1)


Set pvtCache = Application.ActiveWorkbook.PivotCaches.Item(1)

' Handle run-time error if external source is not an OLEDB data source.
On Error GoTo Not_OLEDB

' Check connection setting and make connection if necessary.


If pvtCache.IsConnected = False Then
pvtCache.MakeConnection
End If

' Check if calculated member is valid.


If pvtTable.CalculatedMembers.Item(1).IsValid = True Then
MsgBox "The calculated member is valid."
Else
MsgBox "The calculated member is not valid."
End If

Not_OLEDB:
MsgBox "The source is not an OLEDB data source."
Exit Sub

End Sub
CalculatedMembers.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a CalculatedMembers object.

CalloutFormat Object (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Contains properties and methods that apply to line callouts.

Remarks

Use the Callout property to return a CalloutFormat object.

Example

The following example specifies the following attributes of shape three (a line callout) on myDocument: the
callout will have a vertical accent bar that separates the text from the callout line; the angle between the callout
line and the side of the callout text box will be 30 degrees; there will be no border around the callout text; the
callout line will be attached to the top of the callout text box; and the callout line will contain two segments. For
this example to work, shape three must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(3).Callout
.Accent = True
.Angle = msoCalloutAngle30
.Border = False
.PresetDrop msoCalloutDropTop
.Type = msoCalloutThree
End With
See also

Concepts
Excel Object Model Reference

Other resources
CalloutFormat Object Members

Accent Property

Angle Property

Application Property

AutoAttach Property

AutoLength Property

AutomaticLength Method

Border Property

Creator Property

CustomDrop Method

CustomLength Method

Drop Property

DropType Property

Gap Property
Length Property

Parent Property

PresetDrop Method

Type Property

CalloutFormat.Accent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Allows the user to place a vertical accent bar to separate the callout text from the callout line. Read/write
MsoTriState.

Syntax

expression .Accent

expression A variable that represents a CalloutFormat object.

Remarks

MsoTriState can be one of these MsoTriState constants.

msoCTrue

msoFalse

msoTriStateMixed

msoTriStateToggle

msoTrue. A vertical accent bar separates the callout text from the callout line.

Example

This example adds to myDocument an oval and a callout that points to the oval. The callout text wont have a
border, but it will have a vertical accent bar that separates the text from the callout line.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes
.AddShape msoShapeOval, 180, 200, 280, 130
With .AddCallout(msoCalloutTwo, 420, 170, 170, 40)
.TextFrame.Characters.Text = "My oval"
With .Callout
.Accent = msoTrue
.Border = False
End With
End With
End With
CalloutFormat.Angle Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the angle of the callout line. If the callout line contains more than one line segment, this property
returns or sets the angle of the segment that is farthest from the callout text box. Read/write
MsoCalloutAngleType.

Syntax

expression .Angle

expression A variable that represents a CalloutFormat object.

Remarks

If you set the value of this property to anything other than msoCalloutAngleAutomatic, the callout line maintains
a fixed angle as you drag the callout.

Example

This example sets to 90 degrees the callout angle for a callout named "callout1" on myDocument.

VBA

Set myDocument = Worksheets(1)


myDocument.Shapes("callout1").Callout.Angle = msoCalloutAngle90
CalloutFormat.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.
Syntax

expression .Application

expression A variable that represents a CalloutFormat object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CalloutFormat.AutoAttach Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if the place where the callout line attaches to the callout text box changes depending on whether the origin of
the callout line (where the callout points to) is to the left or right of the callout text box. Read/write MsoTriState.

Syntax

expression .AutoAttach

expression A variable that represents a CalloutFormat object.

Remarks

MsoTriState can be one of these MsoTriState constants.

msoCTrue

msoFalse

msoTriStateMixed

msoTriStateToggle

msoTrue. The place where the callout line attaches to the callout text box changes depending on whether the
origin of the callout line (where the callout points to) is to the left or right of the callout text box.

When the value of this property is True, the drop value (the vertical distance from the edge of the callout text box
to the place where the callout line attaches) is measured from the top of the text box when the text box is to the
right of the origin, and its measured from the bottom of the text box when the text box is to the left of the origin.
When the value of this property is False, the drop value is always measured from the top of the text box,
regardless of the relative positions of the text box and the origin. Use the CustomDrop method to set the drop
value, and use the Drop property to return the drop value.

Setting this property affects a callout only if it has an explicitly set drop value that is, if the value of the
DropType property is msoCalloutDropCustom. By default, callouts have explicitly set drop values when theyre
created.

Example

This example adds two callouts to myDocument. If you drag the text box for each of these callouts to the left of
the callout line origin, the place on the text box where the callout line attaches will change for the automatically
attached callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes
With .AddCallout(msoCalloutTwo, 420, 170, 200, 50)
.TextFrame.Characters.Text = "auto-attached"
.Callout.AutoAttach = True
End With
With .AddCallout(msoCalloutTwo, 420, 350, 200, 50)
.TextFrame.Characters.Text = "not auto-attached"
.Callout.AutoAttach = False
End With
End With
CalloutFormat.AutoLength Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Applies only to callouts whose lines consist of more than one segment (types msoCalloutThree and
msoCalloutFour). Read/write MsoTriState.

Syntax

expression .AutoLength

expression A variable that represents a CalloutFormat object.

Remarks

MsoTriState can be one of these MsoTriState constants.

msoCTrue

msoFalse. The first segment of the callout retains the fixed length specified by the Length property whenever the
callout is moved.

msoTriStateMixed

msoTriStateToggle

msoTrue. The first segment of the callout line (the segment attached to the text callout box) is scaled
automatically whenever the callout is moved.

This property is read-only. Use the AutomaticLength method to set this property to msoTrue, and use the
CustomLength method to set this property to mosFalse.

Example

This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(1).Callout
If .AutoLength Then
.CustomLength 50
Else
.AutomaticLength
End If
End With
CalloutFormat.AutomaticLength Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Specifies that the first segment of the callout line (the segment attached to the text callout box) be scaled
automatically when the callout is moved. Use the CustomLength method to specify that the first segment of the
callout line retain the fixed length returned by the Length property whenever the callout is moved. Applies only to
callouts whose lines consist of more than one segment (types msoCalloutThree and msoCalloutFour).

Syntax

expression .AutomaticLength

expression A variable that represents a CalloutFormat object.

Remarks

Applying this method sets the AutoLength property to True.

Example
This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(1).Callout
If .AutoLength Then
.CustomLength 50
Else
.AutomaticLength
End If
End With
CalloutFormat.Border Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a MsoTriState value that represents the visibility options for the border of the object.

Syntax

expression .Border

expression A variable that represents a CalloutFormat object.

Remarks

The value of this property can be set to one of the following MsoTriState constants:

msoCTrue Does not apply to this object.

msoFalse Sets the border invisible.

msoTriStateMixed Does not apply to this object.

msoTriStateToggle Allows the user to switch the border from visible to invisible and vice versa.

msoTrue default. Sets the border visible.

CalloutFormat.Creator Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CalloutFormat object.

CalloutFormat.CustomDrop Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Sets the vertical distance (in points) from the edge of the text bounding box to the place where the callout line
attaches to the text box. This distance is measured from the top of the text box unless the AutoAttach property is
set to True and the text box is to the left of the origin of the callout line (the place that the callout points to), in
which case the drop distance is measured from the bottom of the text box.

Syntax

expression .CustomDrop(Drop)

expression A variable that represents a CalloutFormat object.

Parameters
Name Required/Optional Data Type Description

Drop Required Single The drop distance, in points.

Example

This example sets the custom drop distance to 14 points, and specifies that the drop distance always be measured
from the top. For the example to work, shape three must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(3).Callout
.CustomDrop 14
.AutoAttach = False
End With
CalloutFormat.CustomLength Method (Excel)

Office 2013 and later


Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Specifies that the first segment of the callout line (the segment attached to the text callout box) retain a fixed
length whenever the callout is moved. Use the AutomaticLength method to specify that the first segment of the
callout line be scaled automatically whenever the callout is moved. Applies only to callouts whose lines consist of
more than one segment (types msoCalloutThree and msoCalloutFour).

Syntax

expression .CustomLength(Length)

expression A variable that represents a CalloutFormat object.

Parameters
Name Required/Optional Data Type Description

Length Required Single The length of the first segment of the callout, in points.

Remarks

Applying this method sets the AutoLength property to False and sets the Length property to the value specified
for the Length argument.

Example

This example toggles between an automatically scaling first segment and one with a fixed length for the callout
line for shape one on myDocument. For the example to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(1).Callout
If .AutoLength Then
.CustomLength 50
Else
.AutomaticLength
End If
End With
CalloutFormat.Drop Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

For callouts with an explicitly set drop value, this property returns the vertical distance (in points) from the edge of
the text bounding box to the place where the callout line attaches to the text box. Read-only Single.

Syntax

expression .Drop

expression A variable that represents a CalloutFormat object.

CalloutFormat.DropType Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a value that indicates where the callout line attaches to the callout text box. Read-only
MsoCalloutDropType.

Syntax

expression .DropType

expression A variable that represents a CalloutFormat object.

Remarks

MsoCalloutDropType can be one of these MsoCalloutDropType constants.

msoCalloutDropCenter

msoCalloutDropMixed

msoCalloutDropBottom

msoCalloutDropCustom

msoCalloutDropTop

If the callout drop type is msoCalloutDropCustom, the values of the Drop and AutoAttach properties and the
relative positions of the callout text box and callout line origin (the place that the callout points to) are used to
determine where the callout line attaches to the text box.

This property is read-only. Use the PresetDrop method to set the value of this property.
Example

This example replaces the custom drop for shape one on myDocument with one of two preset drops, depending on
whether the custom drop value is greater than or less than half the height of the callout text box. For the example
to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(1).Callout
If .DropType = msoCalloutDropCustom Then
If .Drop < .Parent.Height / 2 Then
.PresetDrop msoCalloutDropTop
Else
.PresetDrop msoCalloutDropBottom
End If
End If
End With
CalloutFormat.Gap Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets the horizontal distance (in points) between the end of the callout line and the text bounding box.
Read/write Single.

Syntax

expression .Gap

expression A variable that represents a CalloutFormat object.

Example

This example sets the distance between the callout line and the text bounding box to 3 points for shape one on
myDocument. For the example to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


myDocument.Shapes(1).Callout.Gap = 3
CalloutFormat.Length Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Single value that represents the length (in points) of the first segment of the callout line (the segment
attached to the text callout box.)

Syntax

expression .Length

expression A variable that represents a CalloutFormat object.

CalloutFormat.Parent Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a CalloutFormat object.

CalloutFormat.PresetDrop Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Specifies whether the callout line attaches to the top, bottom, or center of the callout text box or whether it attaches
at a point that?s a specified distance from the top or bottom of the text box.

Syntax

expression .PresetDrop(DropType)

expression A variable that represents a CalloutFormat object.


Parameters
Name Required/Optional Data Type Description

The starting position of the callout line relative to the text


DropType Required MsoCalloutDropType
bounding box.

Example

This example specifies that the callout line attach to the top of the text bounding box for shape one on
myDocument. For the example to work, shape one must be a callout.

VBA

Set myDocument = Worksheets(1)


myDocument.Shapes(1).Callout.PresetDrop msoCalloutDropTop
This example toggles between two preset drops for shape one on myDocument. For the example to work, shape
one must be a callout.

VBA

Set myDocument = Worksheets(1)


With myDocument.Shapes(1).Callout
If .DropType = msoCalloutDropTop Then
.PresetDrop msoCalloutDropBottom
ElseIf .DropType = msoCalloutDropBottom Then
.PresetDrop msoCalloutDropTop
End If
End With
CalloutFormat.Type Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a MsoCalloutType value that represents the callout format type.

Syntax

expression .Type

expression A variable that represents a CalloutFormat object.

CategoryCollection Object (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents the collection of visible chart categories in the chart.


CategoryCollection.Application Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns an Application object that represents the Microsoft Excel application. Read-only.

Syntax

expression .Application

expression A variable that represents a CategoryCollection Object (Excel) object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CategoryCollection.Count Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the CategoryCollection (returns the number of
categories visible in the chart). Read-only.

Syntax

expression .Count

expression A variable that represents a CategoryCollection Object (Excel) object.

CategoryCollection.Creator Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which the specified object was created. Read-only Long.

Syntax

expression .Creator
expression A variable that represents a CategoryCollection Object (Excel) object.

Remarks

Because the object was created in Microsoft Excel, this property returns the hexadecimal value, 5843454C, which
represents the string "XCEL".

Property value

XLCREATOR

CategoryCollection.Creator Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which the specified object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CategoryCollection Object (Excel) object.

Remarks

Because the object was created in Microsoft Excel, this property returns the hexadecimal value, 5843454C, which
represents the string "XCEL".

Property value

XLCREATOR

CategoryCollection.Parent Property (Excel)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns an Object that represents the parent object of the specified CategoryCollection Object (Excel) object.
Read-only.

Syntax

expression .Parent

expression A variable that represents a CategoryCollection Object (Excel) object.

Remarks

This property will return the Chart object that owns this collection of categories.
Property value

OBJECT

CellFormat Object (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents the search criteria for the cell format.

Remarks

Use the FindFormat or ReplaceFormat properties of the Application object to return a CellFormat object.

With a CellFormat object, you can use the Borders , Font , or Interior properties of the CellFormat object, to
define the search criteria for the cell format.

Example

The following example sets the search criteria for the interior of the cell format.

VBA

Sub ChangeCellFormat()

' Set the interior of cell A1 to yellow.


Range("A1").Select
Selection.Interior.ColorIndex = 36
MsgBox "The cell format for cell A1 is a yellow interior."

' Set the CellFormat object to replace yellow with green.


With Application
.FindFormat.Interior.ColorIndex = 36
.ReplaceFormat.Interior.ColorIndex = 35
End With

' Find and replace cell A1's yellow interior with green.
ActiveCell.Replace What:="", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, _
ReplaceFormat:=True
MsgBox "The cell format for cell A1 is replaced with a green interior."

End Sub
Methods

Name

Clear

Properties

Name
AddIndent

Application

Borders

Creator

Font

FormulaHidden

HorizontalAlignment

IndentLevel

Interior

Locked

MergeCells

NumberFormat

NumberFormatLocal

Orientation

Parent

ShrinkToFit

VerticalAlignment

WrapText

See also

Concepts
Excel Object Model Reference

CellFormat.AddIndent Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that indicates if text is automatically indented when the text alignment in a cell is
set to equal distribution (either horizontally or vertically.)

Syntax

expression .AddIndent

expression A variable that represents a CellFormat object.

CellFormat.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a CellFormat object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
CellFormat.Borders Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Borders collection that represents the search criteria based on the cell's border format.

Syntax

expression .Borders

expression A variable that represents a CellFormat object.

Example

This example sets the search criteria to identify the borders of cells that have a continuous and thick style bottom-
edge, creates a cell with this condition, finds this cell, and notifies the user.

Note

The default color of the border is used in this example, therefore the color index is not changed.

VBA

Sub SearchCellFormat()

' Set the search criteria for the border of the cell format.
With Application.FindFormat.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
End With

' Create a continuous thick bottom-edge border for cell A5.


Range("A5").Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
End With
Range("A1").Select
MsgBox "Cell A5 has a continuous thick bottom-edge border"

' Find the cells based on the search criteria.


Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True).Activate
MsgBox "Microsoft Excel has found this cell matching the search criteria."

End Sub
CellFormat.Clear Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Clears the criterias set in the FindFormat and ReplaceFormat properties.


Syntax

expression .Clear

expression A variable that represents a CellFormat object.

CellFormat.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator

expression A variable that represents a CellFormat object.

CellFormat.Font Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Font object, allowing the user to set or return the search criteria based on the cell's font format.

Syntax

expression .Font

expression A variable that represents a CellFormat object.

Example

This example sets the search criteria to identify cells that contain red font, creates a cell with this condition, finds
this cell, and notifies the user.

VBA

Sub SearchCellFormat()
' Set the search criteria for the font of the cell format.
Application.FindFormat.Font.ColorIndex = 3

' Set the color index of the font for cell A5 to red.
Range("A5").Font.ColorIndex = 3
Range("A5").Formula = "Red font"
Range("A1").Select
MsgBox "Cell A5 has red font"

' Find the cells based on the search criteria.


Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True).Activate

MsgBox "Microsoft Excel has found this cell matching the search criteria."

End Sub

CellFormat.FormulaHidden Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that indicates if the formula will be hidden when the worksheet is protected.

Syntax

expression .FormulaHidden

expression A variable that represents a CellFormat object.

CellFormat.HorizontalAlignment Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the horizontal alignment for the specified object.

Syntax

expression .HorizontalAlignment

expression A variable that represents a CellFormat object.


Remarks

The value of this property can be set to one of the following constants:

xlCenter

xlDistributed

xlJustify

xlLeft

xlRight

CellFormat.IndentLevel Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the indent level for the cell or range. Can be an integer from 0 to
15.

Syntax

expression .IndentLevel

expression A variable that represents a CellFormat object.

CellFormat.Interior Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns an Interior object allowing the user to set or return the search criteria based on the cell's interior format.

Syntax

expression .Interior

expression A variable that represents a CellFormat object.


Example

This example sets the search criteria to identify cells that contain a solid yellow interior, creates a cell with this
condition, finds this cell, and notifies the user.

VBA

Sub SearchCellFormat()

' Set the search criteria for the interior of the cell format.
With Application.FindFormat.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

' Create a yellow interior for cell A5.


Range("A5").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("A1").Select
MsgBox "Cell A5 has a yellow interior."

' Find the cells based on the search criteria.


Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True).Activate
MsgBox "Microsoft Excel has found this cell matching the search criteria."

End Sub

CellFormat.Locked Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that indicates if the object is locked.

Syntax

expression .Locked

expression A variable that represents a CellFormat object.

Remarks

This property returns True if the object is locked, False if the object can be modified when the sheet is protected,
or Null if the specified range contains both locked and unlocked cells.

Example
This example unlocks cells A1:G37 on Sheet1 so that they can be modified when the sheet is protected.

VBA

Worksheets("Sheet1").Range("A1:G37").Locked = False
Worksheets("Sheet1").Protect
CellFormat.MergeCells Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

True if the range or style contains merged cells. Read/write Variant.

Syntax

expression .MergeCells

expression A variable that represents a CellFormat object.

CellFormat.NumberFormat Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the format code for the object.

Syntax

expression .NumberFormat

expression A variable that represents a CellFormat object.

CellFormat.NumberFormatLocal Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the format code for the object as a string in the language of the user.

Syntax

expression .NumberFormatLocal

expression A variable that represents a CellFormat object.

CellFormat.Orientation Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the text orientation.

Syntax

expression .Orientation

expression A variable that represents a CellFormat object.

Remarks

The value of this property can be set to an integer value from 90 to 90 degrees or to one of the following
constants:

xlDownward

xlHorizontal

xlUpward

xlVertical

CellFormat.Parent Property (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a CellFormat object.

CellFormat.ShrinkToFit Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that indicates if text automatically shrinks to fit in the available column width.

Syntax

expression .ShrinkToFit

expression A variable that represents a CellFormat object.

CellFormat.VerticalAlignment Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that represents the vertical alignment of the specified object.

Syntax

expression .VerticalAlignment

expression A variable that represents a CellFormat object.

Remarks
The value of this property can be set to one of the following constants:

xlBottom

xlCenter

xlDistributed

xlJustify

xlTop

Example

This example sets the height of row 2 on Sheet1 to twice the standard height and then centers the contents of the
row vertically.

VBA

Worksheets("Sheet1").Rows(2).RowHeight = _
2 * Worksheets("Sheet1").StandardHeight
Worksheets("Sheet1").Rows(2).VerticalAlignment = xlVAlignCenter

CellFormat.WrapText Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns or sets a Variant value that indicates if Microsoft Excel wraps the text in the object.

Syntax

expression .WrapText

expression A variable that represents a CellFormat object.

Remarks

This property returns True if text is wrapped in all cells within the specified range, False if text is not wrapped in
all cells within the specified range, or Null if the specified range contains some cells that wrap text and other cells
that don't.

Characters Object (Excel)

Office 2013 and later

Other Versions
Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents characters in an object that contains text.

Remarks

The Characters object lets you modify any sequence of characters contained in the full text string.

Use Characters(start, length), where start is the start character number and length is the number of characters, to
return a Characters object.

Example

The following example adds text to cell B1 and then makes the second word bold.

VBA

With Worksheets("Sheet1").Range("B1")
.Value = "New Title"
.Characters(5, 5).Font.Bold = True
End With
The Characters method is necessary only when you need to change some of an objects text without affecting the
rest (you cannot use the Characters method to format a portion of the text if the object doesnt support rich text).
To change all the text at the same time, you can usually apply the appropriate method or property directly to the
object. The following example formats the contents of cell A5 as italic.

VBA

Worksheets("Sheet1").Range("A5").Font.Italic = True
Methods

Name

Delete

Insert

Properties

Name

Application

Caption

Count

Creator

Font
Parent

PhoneticCharacters

Text

Characters.Application Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

When used without an object qualifier, this property returns an Application object that represents the Microsoft
Excel application. When used with an object qualifier, this property returns an Application object that represents
the creator of the specified object (you can use this property with an OLE Automation object to return the
application of that object). Read-only.

Syntax

expression .Application

expression A variable that represents a Characters object.

Example

This example displays a message about the application that created myObject.

VBA

Set myObject = ActiveWorkbook


If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
Characters.Caption Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a String value that represents the text of this range of characters.
Syntax

expression .Caption

expression A variable that represents a Characters object.

Characters.Count Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Long value that represents the number of objects in the collection.

Syntax

expression .Count

expression A variable that represents a Characters object.

Example

This example makes the last character in cell A1 a superscript character.

VBA

Sub MakeSuperscript()
Dim n As Integer

n = Worksheets("Sheet1").Range("A1").Characters.Count
Worksheets("Sheet1").Range("A1").Characters(n, 1) _
.Font.Superscript = True
End Sub
Characters.Creator Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a 32-bit integer that indicates the application in which this object was created. Read-only Long.

Syntax

expression .Creator
expression A variable that represents a Characters object.

Characters.Delete Method (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Deletes the object.

Syntax

expression .Delete

expression A variable that represents a Characters object.

Characters.Font Property (Excel)

Office 2013 and later

Other Versions

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns a Font object that represents the font of the specified object.

Syntax

expression .Font

expression A variable that represents a Characters object.

Characters.Insert Method (Excel)

Inserts a string preceding the selected characters.

Syntax

expression .Insert(String)

expression A variable that represents a Characters object.


Parameters
Name Required/Optional Data Type Description

String Required String The string to insert.

Characters.Parent Property (Excel)

Office 2013 and later

Other Versions

Returns the parent object for the specified object. Read-only.

Syntax

expression .Parent

expression A variable that represents a Characters object.

Characters.Text Property (Excel)

Office 2013 and later

Other Versions

Returns or sets the text for the specified object. Read/write String.

Syntax

expression .Text

expression A variable that represents a Characters object.

You might also like