An Example of Looping Over Worksheets


Imagine that (somewhat egotistically) you decide to name all of your worksheets in a workbook after your company name (for us it's Wise Owl). 
Worksheets renamed Wise Owl 1 to 3
Sub RenameWorksheets()
'a reference to each worksheet in the active workbook
Dim ws As Worksheet
'the index number to use
Dim SheetNumber As Integer
SheetNumber = 0
For Each ws In Worksheets
'for each worksheet, rename it
SheetNumber = SheetNumber + 1
ws.Name = "Wise Owl " & SheetNumber
Next ws
End Sub

Comments

Popular posts from this blog

50 Excel VBA Oral Interview Questions