HTSCF Fareha
12-09-2020, 01:23 PM
I was wondering if there was a way to execute a sub on each worksheet inside the same workbook, whose worksheets were consecutively named, until the final worksheet was reached, at which point the sub would exit.
I was thinking something like the following, although I could be way off!
Option Explicit
Sub TestSub()
Dim ws As Worksheet
Dim i As Integer
For i = 1 To 6
Do Until i = 6
' Total of 6 consecutive worksheets to work on, TestData1 through TestData6
Application.ScreenUpdating = False
ThisWorkbook.ws("TestData").Name (i)
' ..... Other bits of code here
i = i + 1
Loop
Application.ScreenUpdating = True
Next i
End Sub
I was thinking something like the following, although I could be way off!
Option Explicit
Sub TestSub()
Dim ws As Worksheet
Dim i As Integer
For i = 1 To 6
Do Until i = 6
' Total of 6 consecutive worksheets to work on, TestData1 through TestData6
Application.ScreenUpdating = False
ThisWorkbook.ws("TestData").Name (i)
' ..... Other bits of code here
i = i + 1
Loop
Application.ScreenUpdating = True
Next i
End Sub