0% found this document useful (0 votes)
92 views

Introduction To Collections in Excel VBA

Collections in Excel VBA allow users to group similar objects together and loop through them. The document lists common collections like Worksheets, ChartObjects, and Names that can be used to loop through sheets, charts, and defined names in a workbook. Examples are provided showing how to loop through the Worksheets and ChartObjects collections to display the names of each item.

Uploaded by

Yamini Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Introduction To Collections in Excel VBA

Collections in Excel VBA allow users to group similar objects together and loop through them. The document lists common collections like Worksheets, ChartObjects, and Names that can be used to loop through sheets, charts, and defined names in a workbook. Examples are provided showing how to loop through the Worksheets and ChartObjects collections to display the names of each item.

Uploaded by

Yamini Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Collections in Excel VBA?

Collection is an object contains group of objects having similar characteristics (with same
properties and methods). For example,if you want to loop through all worksheets in a workbook,
you can refer worksheets collection of the workbook and do whatever you want to do with that
particular worksheet.

Collections in Excel VBA

Below are the most frequently used Collections in the Excel VBA:

Collections Use
We can loop through the installed and available add-in in your
AddIns Collection
Excel. You can use it for finding all available add-ins
We can loop through the all the charts in a Worksheet or
ChartObjects Collection workbook. You can use it for performing some thing with all or
some of the available Charts in the Workbook or Worksheet
Charts Collection It is similar to the above collection
We can loop through the all comments in the workbook and we
Comments Collection
can change any properties of all or some comments
We can loop through the Horizontal page breaks and change the
HPageBreaks Collection
settings
We can loop through the all hyperlinks in the workbook and
Hyperlinks Collection
change the properties
Names Collection We can loop through All names and change the properties
We can loop through all ActiveX controls and change the
OLEObjects Collection
properties
We can loop through the all pivot caches in the workbook and
PivotCaches Collection
change the properties
We can loop through all the pivot tables and change the formats
PivotTables Collection
and other properties
Range Collection We can loop through all ranges
We can loop through shapes including chart in workbook and
Shapes Collection
change the properties
Sheets Collection We can loop through all sheets in the workbbok
Windows Collection We can loop through all windows
We can loop through available or opened workbook and access
Workbooks Collection
their data or change its properties
We can loop through all worksheets in the workbook and change
Worksheets Collection
its properties

Examples Macro File On Collections


Example 1: This code will loop through the Worksheets in a Workbook and display the names of the
worksheets

Private Sub CommandButton1_Click()


Dim sh
For Each sh In ThisWorkbook.Worksheets
MsgBox sh.Name
Next
End Sub

Example 2: This code will loop through the Chart objects in a Worksheet and display the names of
the Chart Objects

Private Sub CommandButton2_Click()


Dim cht
For Each cht In ActiveSheet.ChartObjects
MsgBox cht.Name
Next
End Sub

Download File:

You might also like