Rename worksheet by name in cell, if blank use another cell

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
Hi all,
Macro help---I'm trying to rename a worksheet according to a persons name in a cell, but if that cell is black I need it to the sheet according to another cell.

So in this case, the sheet name would be A6 "John Doe", but if cell A6 is blank then sheet name needs to be A2 "Jane Doe"

Thanks

Screenshot 2021-06-01 132903.jpg
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:
VBA Code:
Sub Name_Sheet()
'Modified  6/1/2021  1:59:49 PM  EDT

If Range("A6").Value = "" Then
    ActiveSheet.Name = Range("A2").Value
Else
    ActiveSheet.Name = Range("A6").Value
End If
End Sub
 
Upvote 0
Thank you that does exactly what I asked, but I should of told you that the sheet already has the name in cell A2.
So I should have said, if cell A6 is blank, then do nothing, otherwise change name to A6. Sorry my bad!
 
Upvote 0
So why are we even talking about A2.
Your now saying if A6 has a value rename sheet. With the value in A6
If A6 is blank do nothing. Is that correct?
 
Upvote 0
Try this:
VBA Code:
Sub Name_Sheet()
'Modified  6/1/2021  3:24:14 PM  EDT

If Range("A6").Value = "" Then
    'Do nothing
Else
    ActiveSheet.Name = Range("A6").Value
End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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