Rename tab based on two cell values

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

can I have some help please on this with some VBA code

i want to rename multiple tabs based on the cell value in each tab

cell values are D8, G15

result would be D8 - G15

is this possible please
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Code:
Sub RenameSheets()
Dim ws As Worksheet, x%, y%
x = 1
For y = 1 To Worksheets.Count
    For Each ws In Worksheets
        On Error Resume Next
        ws.Name = ws.[D8] & " - " & ws.[G15]
        If Err.Number > 0 Then
            ws.Name = "Check " & x
            x = x + 1
        End If
        On Error GoTo 0
    Next
Next
End Sub
If the macro renames any of the sheets "Check" followed by a number, it will be because either there is already a sheet with the required name or there is an invalid sheetname character in D8 and/or G15.
 
Upvote 0
This is not quite working correctly, it renames the first 6 tabs then defaults to the error "Check" even though the [G15] is different
The [D8] value is aleays the same but the [G15] is always different.

Anyone have any idea's on how to fix this please

Sub RenameSheets()
Dim ws As Worksheet, x%, y%
x = 1
For y = 1 To Worksheets.Count
For Each ws In Worksheets
On Error Resume Next
ws.Name = ws.[D43] & " - " & ws.[D5]
If Err.Number > 0 Then
ws.Name = "Check " & x
x = x + 1
End If
On Error GoTo 0
Next
Next
End Sub
 
Upvote 0
It's working for me and I can't replicate the problem.

Post the sheet names and the D8 and G15 values for each sheet.
 
Upvote 0
Sorry Footoo, it my mistake, the file name got to big to rename the tab, once i sorted this it now works find

Thanks for all your help on this
 
Upvote 0
Code:
Sub RenameSheets()
Dim ws As Worksheet, x%, y%
x = 1
For y = 1 To Worksheets.Count
    For Each ws In Worksheets
        On Error Resume Next
        ws.Name = ws.[D8] & " - " & ws.[G15]
        If Err.Number > 0 Then
            ws.Name = "Check " & x
            x = x + 1
        End If
        On Error GoTo 0
    Next
Next
End Sub
If the macro renames any of the sheets "Check" followed by a number, it will be because either there is already a sheet with the required name or there is an invalid sheetname character in D8 and/or G15.
Hey, how can we apply it for only one worksheet? I applied it by selecting the sheet from objects but still, it applies to the workbook.
 
Upvote 0
Welcome to the Board.

which cell gets the name for the sheet? Is it the same sheet?

thx

FS
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top