+ Reply to Thread
Results 1 to 11 of 11

VBA code for default worksheets name

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    VBA code for default worksheets name

    Hi,

    Does anyone how to create default worksheets name?

    I have tried Worksheets("*_1").Select or Worksheets("=*_1").Select both error

    What I want is user can create new worksheets with any name and ending with _1,_2,_3 and so on.

    e.g. Worksheets("David_1").Select or Worksheets("Roams_2").Select


    Regards,
    Farid.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA code for default worksheets name

    Activate the macro recorder, add a new sheet, stop recorder, then you have the code
    If solved remember to mark Thread as solved

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: VBA code for default worksheets name

    Hi patel45,

    It is not such easy way as you mentioned.

    when I said "user" it means that the people who will only run or use macro, not creating or modifying the code.

    Assume that there is 10 existing worksheets in the workbooks. When there is new worksheets required to be created, the administrator will add new one but it needs defaulted sheetname so that macro can recognize the sheets created in order to copy and paste information into Workbooks summary.

    Regards,
    Farid.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA code for default worksheets name

    Hi, Farid,

    you would need to explain why you think to need the name of any new entered worksheet and at which times. If any new worksheet is inserted this is the active sheet by default.

    Please Login or Register  to view this content.
    And this is one of the very few times that any macro recorder code will not shed any light on what you want to do as everything in the code would be hard-coded.

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: VBA code for default worksheets name

    hi HaHobe,

    Please refer to my 2nd post.

    Thanks,
    Farid

  6. #6
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: VBA code for default worksheets name

    So are you saying that the last 2 digits of each Worksheet will be _1, _2 etc and you are trying to select it based on those two digits alone regardless of the preceding text?

  7. #7
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: VBA code for default worksheets name

    Hi greggpetersen75,

    Yes, that is what I want.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA code for default worksheets name

    Hi, Farid,

    sorry but I canīt find any information for coding in that post. Maybe a loop over all worksheets excluding the summary would be good enough to solve the problem.

    ...that macro can recognize the sheets created in order to copy and paste information into Workbooks summary.
    Maybe you should have a look at the codes provided?

    Ciao,
    Holger

  9. #9
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: VBA code for default worksheets name

    Holger's code goes through the name of each worksheet. And the worksheet ending in 3 will become "ws". Then from there, you can just do ws.Select.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA code for default worksheets name

    Hi, Farid,

    check for an underscore before running
    Please Login or Register  to view this content.
    Ciao,
    Holger

  11. #11
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: VBA code for default worksheets name

    Hi HaHobe,

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code to set default value of a combo box
    By rini11 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-23-2013, 05:03 PM
  2. Default to View Code on Form
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2010, 06:11 PM
  3. Apply default chart to multiple worksheets?
    By frankabe in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 07-21-2009, 07:53 PM
  4. Replies: 2
    Last Post: 11-17-2008, 09:14 PM
  5. [SOLVED] Default # of worksheets
    By Lynn in forum Excel General
    Replies: 1
    Last Post: 03-16-2006, 05:30 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1