Allhewrote
New Member
- Joined
- Oct 22, 2024
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
I'm brand new to VBA and am trying to automate some repetitive tasks on workbooks for work purposes. I want to rename each sheet in a workbook to match a value in a cell in DD-MMM-YY format, different in each sheet. From what I've seen in a few different threads I've got this so far:
Sub Rename()
Dim ws As Worksheet
Set ws = ActiveSheet
For i = 1 To ThisWorkbook.Sheets.Count
Sheets(i).Activate
With ActiveSheet
ws.Name = Format(CDate(ws.Range("A1").Value), "DD-MMM-YY")
End With
Next i
End Sub
The code as written takes care of the active sheet when run, regardless of if it is worksheet 1, then skips to the end without formatting any of the subsequent sheets. How Do I make it stop and format each sheet? I keep seeing a mix of recursive loops, for loops, or even a "goto" function. Preference?
Sub Rename()
Dim ws As Worksheet
Set ws = ActiveSheet
For i = 1 To ThisWorkbook.Sheets.Count
Sheets(i).Activate
With ActiveSheet
ws.Name = Format(CDate(ws.Range("A1").Value), "DD-MMM-YY")
End With
Next i
End Sub
The code as written takes care of the active sheet when run, regardless of if it is worksheet 1, then skips to the end without formatting any of the subsequent sheets. How Do I make it stop and format each sheet? I keep seeing a mix of recursive loops, for loops, or even a "goto" function. Preference?