VBA Loop on sheets in Excel file

Опубликовано: 03 Апрель 2026
на канале: Simplified Excellence
56
0

Loop on all sheets in an Excel file.

Code:
Sub loop_on_sheets_in_current_file()

Dim current_file As Workbook
Dim ws_sheet As Worksheet

'identify current_file
Set current_file = ActiveWorkbook

'loop on all sheets
For i = 1 To current_file.Worksheets.Count

'identify sheet in the loop
Set ws_sheet = current_file.Worksheets(i)

'code here

'display name of sheet
MsgBox ("The current worksheet, in position " & i & " has the following name: " & ws_sheet.Name)

Next

End Sub

-------------------------------
NEED HELP?
-------------------------------
Leave a comment with your questions, issues or projetcs and I will try to answer with a video.

-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!