+ Reply to Thread
Results 1 to 8 of 8

Code to rename worksheet based on combobox selection that works with protected sheet

  1. #1
    Registered User
    Join Date
    08-05-2013
    Location
    DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Code to rename worksheet based on combobox selection that works with protected sheet

    I have a worksheet for employees to report their time and expenses. In this worksheet, I added an Activex combobox list for a particular employee to select his/her name from (the list references the employee names from another sheet that will be hidden).

    I would like the time and expense worksheet to automatically rename to some abbreviation of the employee name selected from the combobox when the worksheet is protected.

    I was able to write working code that updates the sheet name based on the linkedcell that the combobox selection outputs to, however this will not work when the sheet is protected because Excel doesn't seem to recognize the selectionchange. My question: How can I make sure the worksheet name auto updates when the sheet is protected? I'm pretty sure there is a way to use Private Sub ComboBox41_Click() to do what I want, but I'm not sure how to do it.

    I've tried auto renaming the worksheet using data validation list, form combo box, and activex combo box and I run into the same problem when protecting the sheet. That is, the selection event is not being recognized when sheet protection is on.

    The code I currently have is copied below (it does work when the sheet isn't protected). Note that N9 references a formula based off of the linkedcell that abbreviates the employee name.

    Please Login or Register  to view this content.
    I've looked for hours and have not found similar posts. Thanks so much for the help.

    - Nina
    Last edited by natkin; 08-05-2013 at 03:16 PM. Reason: Updated title and content

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    Hi Nina. If your code works on an unprotected sheet, try this code.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-05-2013
    Location
    DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    Thanks for your quick response. I forgot to mention that I was using code to protect the sheet to allow for grouping/ungrouping. Sorry about that. The code I used to protect the worksheet is below:

    Please Login or Register  to view this content.
    I temporarily erased the sheet protection code to run the code you sent and it works to update the worksheet name after I manually protected the sheet, but it didn't seem to re-protect the sheet after it was renamed. Does that make sense?

    I'll continue working on it, but I would really appreciate some more of your feedback, especially incorporating the protection code I already have above. This seems to be on the right track.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    From looking at your code, it appears that when you open the workbook, the sheet is protected with the password "password" but allows grouping. Then when you enter data in F9, you want to re-name the sheet to the value of F9 but the cell may contain illegal characters. Is this correct? What kind of illegal characters are we talking about? If you could post a copy of your file it would also help.

  5. #5
    Registered User
    Join Date
    08-05-2013
    Location
    DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    Your understanding is correct.

    The illegal characters just refers to a potential for blank names in the drop down list since a worksheet name can't be blank. I put the error there based on what I read in other forums, but it shouldn't make a difference with the way I currently have things set up.

    I'm attaching a test spreadsheet since that should hopefully help. To unprotect, type "password". Let me know if you have any more questions. I've tried playing around with the code, but still can't get the renaming to work properly. I'm not tied to any particular method of coding as long as it works.
    Attached Files Attached Files

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    After looking at your file, I noticed that you want to re-name the sheet according to the value of N9 not F9. Cell N9 has a formula in it wich is based on E10 which itself is based on a drop down with names. I tried choosing different names but it didn't have any effect on N9. I couldn't quite figure out how the formulae worked. In the attached file, you will notice that I simply created a drop down list in cell P9 of the dates in sheet "Startdate", range A2:A19. I also changed the code in the worksheet module to refer to P9. When you choose a date from the drop down in P9, the sheet is re-named accordingly. This seems to work the way you wanted. I hope this helps. Maybe you could incorporate it in your sheet to make it work for you.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-05-2013
    Location
    DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    Thanks! I meant N9, not F9. Sorry for any confusion. I missed the "F" in your sentence.

    I looked at the file you sent. I'm getting a run-time error '1004' when I try to change the date. I'll play around with the code some more to see if I can incorporate it. Thanks again for your help.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Code to rename worksheet based on combobox selection that works with protected sheet

    I', not sure why you're getting an error. When I try the file I last posted, it works fine if I use the drop down in P9. Good luck with it.

+ 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] Based on userform combobox selection find text on worksheet
    By afpPaul in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 08:07 AM
  2. [SOLVED] Change Worksheet based on ComboBox selection
    By dagindi in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-15-2012, 10:19 AM
  3. ActiveX ComboBox listfillrange automatic update
    By Makafi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2009, 01:54 PM
  4. Populate a activeX combobox from a selection of another combobox
    By ptramel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2009, 06:50 PM
  5. ActiveX ComboBox selection writes multiple cells
    By darmstrong in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-30-2007, 10:31 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