VBA Chart Project - Loop Through All Charts in a Workbook (Code Included)

Опубликовано: 06 Октябрь 2024
на канале: EverydayVBA
1,534
12

This video is number five in our color chart project. In this video, we loop through every single sheet in a workbook, and we loop through every single chart. To do this, we declare a worksheet object, and we also declare a chart object. Then we use a For Loop to loop through each sheet and each chart object. To make the code easier to understand, we add some select statements. Also, we use a message box (MSGBOX) as we loop through the charts to show what chart is active.

We also show you how to change the name of a Chart in the upper left by the formula bar.

This video is perfect for someone looking at how to go through every sheet and every chart, and in the future videos, we will be showing how we put all of this together so that you can easily color a chart based on a cell color.

==========================
'CODE
==========================
Sub ScratchSheetandChartO()

Dim sht As Worksheet
Dim cht As ChartObject

For Each sht In Worksheets
sht.Select
For Each cht In sht.ChartObjects
cht.Activate
cht.Select
MsgBox "Chart " & cht.Name & " is now active"
Next
Next

End Sub