+ Reply to Thread
Results 1 to 13 of 13

Changing Worksheet names based on cell value with VBA

  1. #1
    Registered User
    Join Date
    02-04-2013
    Location
    Palatine, IL USA
    MS-Off Ver
    Excel 2016
    Posts
    34

    Changing Worksheet names based on cell value with VBA

    I have a workbook made up with all my sheets ready for data. I want a VBA script that will rename the worksheet as soon as i change the cell value.

    I am using cell A1 to condense two cells into one name using this formula:
    =IF(OR(K2="",N2=""),"",CONCATENATE(N2," ",K2))

    So i want to run a worksheet rename based off A1.
    I have given generic names to the worksheet so they are place holders, i do not need to create a new sheet. And i also want the script to only be able to be applied to the 20 specific sheets. (27 total sheets in workbook)

    Can anyone help? My VBA skills are nill

    Thanks in advance.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Changing Worksheet names based on cell value with VBA

    Check out a sample
    https://www.youtube.com/watch?v=HsB3Wz8B9Sg

  3. #3
    Registered User
    Join Date
    02-04-2013
    Location
    Palatine, IL USA
    MS-Off Ver
    Excel 2016
    Posts
    34

    Re: Changing Worksheet names based on cell value with VBA

    thanks but i followed step by step and got nothing. I am using a formula in cell A1 to create text could that be causing issues? also will i have to do this for each of the worksheets that i want the macro to work with? If not, how do i discriminate the pages i dont want the macro to run on?

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Changing Worksheet names based on cell value with VBA

    Ah yes, you would have to use sheet calculate, not sheet change.

    How many sheets would you be dealing with?

  5. #5
    Registered User
    Join Date
    02-04-2013
    Location
    Palatine, IL USA
    MS-Off Ver
    Excel 2016
    Posts
    34

    Re: Changing Worksheet names based on cell value with VBA

    i have 27 sheets total

    20 of them are the ones i want the macro to run on.
    they are ID'd in the VBA editor as sheet 2,5,10-27

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Changing Worksheet names based on cell value with VBA

    Possibly in the workbook module, for example you and add more sheets that you don't want to include,

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-04-2013
    Location
    Palatine, IL USA
    MS-Off Ver
    Excel 2016
    Posts
    34

    Re: Changing Worksheet names based on cell value with VBA

    Im getting nothing, no change in name and not even an error message

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Changing Worksheet names based on cell value with VBA

    .
    Place this code in the ThisWorkbook module:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-04-2013
    Location
    Palatine, IL USA
    MS-Off Ver
    Excel 2016
    Posts
    34

    Re: Changing Worksheet names based on cell value with VBA

    Thanks this worked!!! you guys are great

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Changing Worksheet names based on cell value with VBA

    Glad to help

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: Changing Worksheet names based on cell value with VBA

    Thanks for the Add Rep

  12. #12
    Registered User
    Join Date
    06-14-2019
    Location
    Andover KS
    MS-Off Ver
    7
    Posts
    8

    Re: Changing Worksheet names based on cell value with VBA

    Hello, and thank you in advance for any advice. I have 22 queries to export to Excel from Access 2010. [B]DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "NAME_01", "\\corp\data\fac_gen\6C45S - STOCK PARTS CRIB\Open PO's Data\FINAL_PRODUCT_FOR_MAIL\OPEN_POs_PROJECT.XLSX", -1, "NAME_01".
    Rather than have the query export as "Name_01", I would like to have it change dynamically to match the worksheet in the same workbook named "Planners", and to match B2. Name_02, would be the same, only B3 and so on through B23. Name_01=B2, Name_02=B3, Name_03=B4 and so on. I have tried :

    Dim xl As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet

    Set xl = New Excel.Application
    Set xlBook = xl.Workbooks.Open("\\corp\data\fac_gen\6C45S - STOCK PARTS CRIB\Open PO's Data\FINAL_PRODUCT_FOR_MAIL\OPEN_POs_PROJECT.XLSX")

    Set xlSheet = xlBook.Worksheets(4)



    xlSheet.Name = "test"
    'test line above I tried to enter a path, but no luck.*******************************************************************************

    xl.DisplayAlerts = False
    xlBook.Save
    xlBook.Close True
    xl.Quit
    xl.DisplayAlerts = True

    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xl = Nothing

    I am using a kill command in Access to delete the spreadsheet prior to rebuilding it with Access each day, so I can't use macros within Excel and they would be deleted every day. Thanks!

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Changing Worksheet names based on cell value with VBA

    tragatz1,

    Welcome to the forum, however:

    You need to start your own thread if you want help, jumping on an old one from a year and a half ago, and not even related in subject (which would not really make a difference), won't get you any help. Sorry, not trying to be difficult, but it just doesn't work that way. Also, please check the forum rules, you need to use code tags when posting code.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

+ 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. [SOLVED] Need to find way to distribute names from one worksheet to another based on cell values
    By pongmeister in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-09-2015, 04:56 PM
  2. [SOLVED] Renaming worksheets names based on cell value in main worksheet
    By a-man in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2015, 12:45 PM
  3. Changing Sheet Names based on cell value - Object doesnt support this property error
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2013, 09:30 AM
  4. Changing Sheet Names based on a Cell Reference
    By tjloggia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2012, 04:35 PM
  5. Changing Sheet Names Based on # Values in Names
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2010, 03:34 PM
  6. changing worksheet names in VBA
    By Kimberly in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-07-2006, 04:44 PM
  7. Changing VB Component Names to match Worksheet names using VBE
    By Philip in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2005, 01:06 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