Good day guys, I'm sure someone will be able to help me.
I'm new to VBA (know nothing) and found a macro i can use to rename my tabs to cell values on each new worksheet, sometimes over a hundred worksheets(time sheets) depending on the amount of guys on site. It works well but i need three other worksheets to stay unchanged.
The code:
Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 1 To Sheets.Count
If Sheets(i).Range("U17").Value = "" Then
Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in U17. Fix sheet, then rerun."
MsgBox Msg, vbExclamation
Exit Sub
Else
On Error GoTo ErrSheetName
Sheets(i).Name = Sheets(i).Range("U17").Value
On Error GoTo 0
End If
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation
End Sub
I'm new to VBA (know nothing) and found a macro i can use to rename my tabs to cell values on each new worksheet, sometimes over a hundred worksheets(time sheets) depending on the amount of guys on site. It works well but i need three other worksheets to stay unchanged.
The code:
Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 1 To Sheets.Count
If Sheets(i).Range("U17").Value = "" Then
Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in U17. Fix sheet, then rerun."
MsgBox Msg, vbExclamation
Exit Sub
Else
On Error GoTo ErrSheetName
Sheets(i).Name = Sheets(i).Range("U17").Value
On Error GoTo 0
End If
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation
End Sub