07-27-2023, 09:42 AM
Example:
Sub PrintWorksheetNames()
Dim ws As Worksheet
'Loop through each worksheet in the active workbook
For Each ws In ThisWorkbook.Sheets
Debug.Print ws.Name
Next ws
End Sub
Explanation:
The code defines a subroutine named PrintWorksheetNames.
It declares a variable ws of type Worksheet, which will be used to loop through each worksheet in the active workbook.
The For Each loop iterates through each worksheet in the ThisWorkbook.Sheets collection.
The Debug.Print statement is used to print the name of each worksheet in the Immediate window, which can be accessed by pressing Ctrl + G.
Sub PrintWorksheetNames()
Dim ws As Worksheet
'Loop through each worksheet in the active workbook
For Each ws In ThisWorkbook.Sheets
Debug.Print ws.Name
Next ws
End Sub
Explanation:
The code defines a subroutine named PrintWorksheetNames.
It declares a variable ws of type Worksheet, which will be used to loop through each worksheet in the active workbook.
The For Each loop iterates through each worksheet in the ThisWorkbook.Sheets collection.
The Debug.Print statement is used to print the name of each worksheet in the Immediate window, which can be accessed by pressing Ctrl + G.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos