Looping in cell
Sub Cell_Loop()
Dim cell As Range
'Loop through each cell in a cell range
For Each cell
In ActiveSheet.Range("A1:Z100")
Debug.Print
cell.Value
Next cell
'Loop through each cell in a Named Range
For Each cell
In ActiveSheet.Range("RawData")
Debug.Print
cell.Value
Next cell
'Loop through each cell in a Table body range
For Each cell
In ActiveSheet.ListObjects("Table1").DataBodyRange
Debug.Print
cell.Value
Next cell
End Sub
Looping in chart
Sub Chart_Loop()
Dim sht As Worksheet
Dim cht As ChartObject
'Loop through each chart in the active workbook
For Each sht
In ActiveWorkbook.Worksheets
For Each cht
In sht.ChartObjects
Debug.Print cht.Name
Next cht
Next sht
End Sub
Looping Through shapes
Sub Shape_Loop()
Dim sht As Worksheet
Dim shp As Shape
'Loop through each shape in the active workbook
For Each sht
In ActiveWorkbook.Worksheets
For Each shp
In sht.Shapes
If
shp.Type = msoAutoShape Then
Debug.Print shp.Name
End If
Next shp
Next sht
End Sub
No comments:
Post a Comment