VBA command to update sheet name from cell

Velz

New Member
Joined
Jun 22, 2011
Messages
2
Hi Everyone, I apologize in advance for my rudimentary excel skills - I'm just learning this fantastic language. In my current project, I would like to have a sheet name updated based on a user input into a specific cell. I am currently using the formula:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
Name = [b1].Text
End If
End Sub

What I wish to accomplish is to have a user input a name into a previous sheet, and have that input become this sheets name. Is this possible? and if so, please help!

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello and Welcome,

The code below should give you a start.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If (Intersect(Target, Range("B1")) Is Nothing) Then Exit Sub
    On Error GoTo ErrorHandler
    Dim lngIndex As Long
    Dim strName As String
 
    lngIndex = ActiveSheet.Index
    strNewName = ActiveSheet.Range("B1")
 
    Worksheets(lngIndex + 1).Name = strNewName
    Exit Sub
ErrorHandler:
    MsgBox "Not able to rename Sheet(" & lngIndex _
        & ") to " & strNewName
End Sub

This code will generate an error message in these two cases:
If the ActiveSheet is the last sheet in the workbook
If the New Sheet Name is being used by another worksheet

You could improve the code by testing for those conditions first and taking some other action.
(for example, if it is the last sheet- add a new sheet).

Good luck! :)
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,877
Members
452,949
Latest member
Dupuhini

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