Hello There,
I have a workbook with 3 worksheets. Each worksheet has it's own defined User Name (eg. Invoices, Journals, Setup, etc.)
I would like to do the following in a single Sub:
1. Define the Worksheet Code and the Worksheet Name in an Array
....(Sheet1 = Invoices, Sheet8 = Journals, Sheet5 = Setup, etc.)
2. Loop through all the worksheets in the workbook:
.....a. Check if the current loop record's, worksheet codename and worksheet name exists in the Array (worksheet codename and worksheet name)
...............If it does not exist then delete the worksheet (eg. Sheet7 = Junk, delete it)
...............If the worksheet codename exists and the name is different as compared in the array, then assign the actual worksheet name from the array to the worksheet
...............(eg. Sheet1 = Blank, then this should be renamed to Invoices)
I managed to write the below code:
Appreciate your help.
Thank & regards,
Don
I have a workbook with 3 worksheets. Each worksheet has it's own defined User Name (eg. Invoices, Journals, Setup, etc.)
I would like to do the following in a single Sub:
1. Define the Worksheet Code and the Worksheet Name in an Array
....(Sheet1 = Invoices, Sheet8 = Journals, Sheet5 = Setup, etc.)
2. Loop through all the worksheets in the workbook:
.....a. Check if the current loop record's, worksheet codename and worksheet name exists in the Array (worksheet codename and worksheet name)
...............If it does not exist then delete the worksheet (eg. Sheet7 = Junk, delete it)
...............If the worksheet codename exists and the name is different as compared in the array, then assign the actual worksheet name from the array to the worksheet
...............(eg. Sheet1 = Blank, then this should be renamed to Invoices)
I managed to write the below code:
Code:
Sub wsloop()
Dim ws As Worksheet
For Each ws In Worksheets
MsgBox ws.CodeName & " " & ws.Name
Next ws
End Sub
Appreciate your help.
Thank & regards,
Don