Loop through worksheets and print their names in the immediate window - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Loop through worksheets and print their names in the immediate window (/showthread.php?tid=5253) |
Loop through worksheets and print their names in the immediate window - Qomplainerz - 07-27-2023 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. |