Tab naming

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Right click the sheet tab and select View Code. Paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A1" Then
    On Error Resume Next
        Me.Name = Target.Value
    On Error GoTo 0
End If
End Sub

Then close the code window. What you enter in A1 will become the sheet's name (provided that it is a 'legal' sheet name).
 
Upvote 0
What if the sheet does not exist before the macro runs? i.e. the macro first creates a sheet, data is pasted onto it and the tab name is based on one of the cell values.
 
Upvote 0
Do you mean something like

Code:
Sub test()
Dim ws As Worksheet
Set ws = Worksheets.Add
Sheets("Sheet2").Range("A1:C10").Copy Destination:=ws.Range("A1")
Application.CutCopyMode = False
On Error Resume Next
ws.Name = ws.Range("A1").Value
On Error GoTo 0
End Sub
 
Upvote 0
Well, yes and no. I already have the code set for adding the new sheet and pasting the data. The only part I cannot get to work is the naming of the tab. How do I make it name the tab what the value is on cell K2 on the active sheet?
 
Upvote 0
Code:
Sub inputit()
'
' inputit Macro
' Macro recorded 7/12/2008 by IT
' Modified on 9/4/2008 by ML
'
'
    Sheets("FrontPage").Select
    Sheets.Add
    Range("B2").Select
    ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
        False
'
'
' Change location text color and alignment
'
'
    Range("B10").Select
    Selection.Font.ColorIndex = 0
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
'
' Delete all the picures
'
Dim obj
For Each obj In ActiveSheet.Shapes: obj.Delete: Next
'
' Delete the top rows
'
    Rows("1:8").Select
    Selection.Delete Shift:=xlUp
'
'Change tab name and back to FrontPage'

    Sheets("FrontPage").Select
    Range("K2").formula = "=SUBSTITUTE(MID(B2,53,9),"":"",""-"")"
'
'   this is where I want to have the tab named
'
    Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Columns("B:B").ColumnWidth = 66
    Sheets("FrontPage").Select
    Range("B1").Select
'
End Sub
 
Last edited by a moderator:
Upvote 0
Try

Rich (BB code):
    Sheets("FrontPage").Select
    Range("K2").Formula = "=SUBSTITUTE(MID(B2,53,9),"":"",""-"")"
'
'   this is where I want to have the tab named
'
    On Error Resume Next
    ActiveSheet.Name = Range("K2").Value
    On Error GoTo 0
    Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0
Thanks for that. I did have to remove the line:

Sheets("FrontPage").Select

It was activating another sheet, I want the rest of the actions to take place on teh newly inserted sheet. That was probably there from my bad tinkering.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,225,367
Messages
6,184,542
Members
453,241
Latest member
rahuldev31

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