Consulting

Results 1 to 5 of 5

Thread: Rename sheets from cell in active sheet

  1. #1
    VBAX Regular
    Joined
    Aug 2005
    Posts
    8
    Location

    Question Rename sheets from cell in active sheet

    Hi All,

    Using the code below I'm attempting to rename my worksheet by using a string (or number) contained in cell E4 for example that's present on the same active sheet. The loop steps through a pivot table to create a new sheet for each consecutive cell selected. After each new sheet is created, I'd like to rename it using the string (or number) contained in cell "E4". So far I've had no success with the code below. Can anyone help me with this stumbling block? Thanks.

    spflash


    [VBA]
    Sub PivotTable
    Dim TB As Worksheet
    Dim FinalRow As Long
    ActiveSheet.Name = "PivotTable"
    For i = 5 To Final Row
    Cells(i, 3).Select
    Selection.ShowDetail = True
    Active Sheet.Name=TB.Range ("E4")
    Sheets ("PivotTable").Select
    Next i
    End Sub
    [/VBA]

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Try this:


    [VBA] ThisWorkbook.SaveAs Range("Your cell here").Value & ".xls" [/VBA]
    Peace of mind is found in some of the strangest places.

  3. #3
    VBAX Regular
    Joined
    Aug 2005
    Posts
    8
    Location

    Rename sheets from cell in active sheet

    austenr,

    Thank you for your help. It is greatly appreciated. But how do I apply this
    piece of code in my macro.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    this goes in the code for the worksheet you wish to change the name on and works on any change in the sheet:
    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address = "$A$1" Then
    Me.Name = Range("A1").Value
    End If
    End Sub
    [/VBA]

    whatever you put in cell A1 will be the name of the sheet. Maybe it will get you a start.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Aug 2005
    Posts
    8
    Location

    Rename sheets from cell in active sheet

    lucas,

    Thank you for your input. I greatly appreciate the help.
    I will try the code A.S.A.P.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •