<< Click to Display Table of Contents >> Columns (collection) |
Access paths for the columns of a worksheet:
▪Application à Workbooks à Item à Sheets à Item à Columns
▪Application à Workbooks à Item à ActiveSheet à Columns
▪Application à ActiveWorkbook à ActiveSheet à Columns
▪Application à ActiveSheet à Columns
▪Application à Columns
Access paths for the columns of arbitrary ranges:
▪Application à Workbooks à Item à Sheets à Item à Range à Columns
▪Application à Workbooks à ActiveSheet à Range à Columns
▪Application à ActiveWorkbook à ActiveSheet à Range à Columns
▪Application à ActiveSheet à Range à Columns
▪Application à Range à Columns
Access paths for the columns of entire table columns:
▪Application à Workbooks à Item à Sheets à Item à Rows à Item à Columns
▪Application à Workbooks à ActiveSheet à Rows à Item à Columns
▪Application à ActiveWorkbook à ActiveSheet à Rowsà Item à Columns
▪Application à ActiveSheet à Rowsà Item à Columns
▪Application à Rowsà Item à Columns
Access paths for the columns in the currently selected cells:
▪Application à Workbooks à Item à Sheets à Item à Selection à Columns
▪Application à Workbooks à ActiveSheet à Selection à Columns
▪Application à ActiveWorkbook à ActiveSheet à Selection à Columns
▪Application à ActiveSheet à Selection à Columns
▪Application à Selection à Columns
1 Description
Columns is a collection of all columns in a worksheet or range. The individual elements of this collection are of the type Range, which allows you to apply all properties and methods available for Range objects to them.
2 Access to the object
Columns can be the child object of two different objects:
▪As a child object of a Sheet object, it represents all columns of this worksheet.
▪As a child object of a Range object, it represents all columns of this range.
Examples for Columns as a child object of a Sheet object:
' Display the number of columns in the current worksheet
MsgBox pm.ActiveSheet.Columns.Count
' Format the first column in the worksheet in boldface
pm.ActiveSheet.Columns(1).Font.Bold = True
Examples for Columns as a child object of a Range object:
' Display the number of columns in the specified range
MsgBox pm.ActiveSheet.Range("A1:F50").Columns.Count
' Format the first column in a range in boldface
pm.ActiveSheet.Range("A1:F50").Columns(1).Font.Bold = True
3 Properties, objects, collections and methods
Properties:
▪Count R/O
Objects:
▪Item → Range (default object)
▪Application → Application
Count (property, R/O)
Data type: Long
Returns the number of Range objects in the Columns collection – in other words: the number of the columns in the worksheet or range.
Item (pointer to object)
Data type: Object
Returns an individual Range object, i.e. a range that contains one individual column.
Which Range object you get depends on the numeric value that you pass to Item: 1 for the first column, 2 for the second, etc.
Example:
' Set the font for second column in the worksheet to Courier New
pm.ActiveSheet.Columns.Item(2).Font.Name = "Courier New"
Application (pointer to object)
Returns the Application object.
Parent (pointer to object)
Returns the parent object, i.e. an object that is either of the type Sheet or Range .