Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop through worksheets and print their names in the immediate window
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through columns and clear contents Qomplainerz 0 240 07-27-2023, 11:21 AM
Last Post: Qomplainerz
  Loop to fill numbers in cells with VBA Qomplainerz 0 228 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Loop to display numbers in VBA Qomplainerz 0 226 07-27-2023, 07:33 AM
Last Post: Qomplainerz
  Do Until loop in VBA Qomplainerz 0 177 07-26-2023, 08:34 PM
Last Post: Qomplainerz
  Do While loop in VBA Qomplainerz 0 193 07-26-2023, 08:33 PM
Last Post: Qomplainerz
  For...Next loop in VBA Qomplainerz 0 207 07-26-2023, 08:32 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)