+ Reply to Thread
Results 1 to 5 of 5

Help with protecting only certain cells based on a cells contents

  1. #1
    Registered User
    Join Date
    10-22-2012
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2002 + 2010 + MAC 2010
    Posts
    15

    Help with protecting only certain cells based on a cells contents

    Hi All

    I am hoping that some one will be able to solve a problem i have with the attached file. Once a column has 8 entries between row 9 and 28 i want to protect all the cells to stop anymore being entered. this works but after a number of the columns between B and BK cells which should not be protected become protected?!

    Any help/advice would be appriciated.

    (Also any help on making the vba code more streamlined would also be appriciated!!)
    Attached Files Attached Files

  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: Help with protecting only certain cells based on a cells contents

    Hello Christopher. Copy this code into the worksheet module (not a regular module). It will allow you to enter data into up to 8 cells in each column. When you try to enter data into the 9th cell, you get a warning message. I hope this does what you were looking for.


    Private Sub Worksheet_Change(ByVal Target As Range)
    Please Login or Register  to view this content.
    Last edited by Mumps1; 01-18-2013 at 02:55 PM.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with protecting only certain cells based on a cells contents

    You don't need VBA for this. Standard in-cell data validation will limit the number of entries allowed in any one column like so....

    1) Unprotect the sheet, not needed.
    2) Remove the Workbook_SheetChange macro in ThisWorkbook for now, it's not needed for this either
    3) Highlight B9:BK28
    4) Alt-D-L will open the data validation window
    5) Apply the following settings on the highlighted cells:

    Allow: Custom
    Formula: =COUNTA(B$9:B$28)<9 (this formula will adjust itself for each column)

    Click ERROR ALERT tab
    Title: Maximum entries reached
    Error Message: No more entries allowed. To enter a value in this cell you will need to remove one from another cell in this column.

    MaxEntries.jpg



    The main benefit here besides no VBA to manage, you can remove an entry in another cell and put one in a different cell, should be much friendlier to the user.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    10-22-2012
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2002 + 2010 + MAC 2010
    Posts
    15

    Re: Help with protecting only certain cells based on a cells contents

    Thanks both for the help, both solutions are great! but raise another problem for me. What if i want to go over the set limit of 8? with the data validation it will not let me do this with out amending it.

    basically i need the normal user to be able to take it the limit set and not go over or be able to remove what has been entered, and i need a 'authorised' person who can take it over the limit and remove entries if needed - does this make sense? thanks again for your help

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with protecting only certain cells based on a cells contents

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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