Add Worksheet, Name it & Put Name in Cell

  • Hi,


    I am trying to write a program in vba that will create a new worksheet at the end of the workbook and name it to what i want. Then i require the name of the worksheet to be placed in a cell on a different page of the workbook. So far i have managed to create the new worksheet but cannot figure out how to tell the program to place the name of the new worksheet into a cell on a different page.

  • Re: Worksheet Tabs


    You could try something like:


    Code
    Sheets("Sheet3").Range("A1").Value = ActiveSheet.Name


    This codes assumes you want to put the sheet name in A1 on sheet "Sheet3" and that the new sheet is the active sheet.


    Regards,

    Barrie Davidson
    My Excel Web Page
    "You're only given a little spark of madness. You mustn't lose it." - Robin Williams

  • Re: Worksheet Tabs


    I have written this for you, take care that only a-z [A-Z] and 0-9 are used in cell A1 as tab names can get fussy and the code will bug also the datastream should not be toooo long suggest under 10 characters just in case.


    Jack


    BTW my code is very locked and not as flexable as you might like, you shold be able to edit to your requirements as the code i hope is quite understandable and editable.

  • Re: Worksheet Tabs



    Thank you very much. That was exactly what i was looking for.


    Very Kindest Regards

  • Re: Worksheet Tabs


    Quote from Jack in the UK

    I have written this for you, take care that only a-z [A-Z] and 0-9 are used in cell A1 as tab names can get fussy and the code will bug also the datastream should not be toooo long suggest under 10 characters just in case.


    Jack


    BTW my code is very locked and not as flexable as you might like, you shold be able to edit to your requirements as the code i hope is quite understandable and editable.


    Thank you for taking the time to answer my question. Although this code works it is not what i was looking for.
    Thank you again for your help.


    Kindest Regards

  • Re: Worksheet Tabs


    I see Barry has done this for you. The code below might still of some use though.


    Code
    Sub AddSheetAndName()
    Dim wSheet As Worksheet
    
    
    Set wSheet = Worksheets.Add(After:=Sheets(Sheets.Count))
        With wSheet
             .Name = "MyNewSheet"
             .Range("A1") = .Name
        End With
    End Sub
  • Re: Add Worksheet, Name it & Put Name in Cell


    Quote from "VBA"

    Set wSheet = Worksheets.Add(After:=Sheets(Sheets.Count))
    With wSheet
    .Name = "MyNewSheet"
    .Range("A1") = .Name
    End With


    This is really usefull for what i am doing, but if for example i called a worksheet number 1 how can i get it so that as soon as the code add a worksheet it automatically calls it number 2, then adding another will call it number 3 and so on

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!