+ Reply to Thread
Results 1 to 3 of 3

Help Fixing Cell Range Clear Button

  1. #1
    Registered User
    Join Date
    08-27-2018
    Location
    London
    MS-Off Ver
    office 2016
    Posts
    45

    Help Fixing Cell Range Clear Button

    Can you please help fix the clear button in SetUp as currently it is throwing an error

    Sub Rectangle3_Click()

    With Sheets("£SAFE LOG")
    .Unprotect Password:="cream"
    With .Range("B9:H9, B12:H12, B19:H19, B21:h21, B31:H31")
    .ClearContents
    .Locked = False
    End With
    End With
    End Sub

    The code in the safe log sheet was originally like

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("b9:h9, b12:h12, b19:h19, b21:h21, b31:h31")) Is Nothing Then Exit Sub
    ActiveSheet.Unprotect Password:="cream"
    Target.Locked = True
    ActiveSheet.Protect Password:="cream"
    End Sub

    but was changed to

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("b9:h9, b12:h12, b19:h19, b21:h21, b31:h31")) Is Nothing Then Exit Sub
    If Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    ActiveSheet.Unprotect Password:="cream"
    Target.Locked = True
    ActiveSheet.Protect Password:="cream"
    Application.EnableEvents = True
    End Sub

    This was to prevent the cells from locking when the cell had no input , for example when a user pressed delete the cell would lock even without typing anything. However the change broke the code in the clear button.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Help Fixing Cell Range Clear Button

    change highlighted line.

    HTML Code: 
    1. Click on the * Add Reputation if you think this helped you
    2. Mark your thread as SOLVED when question is resolved

    Modytrane

  3. #3
    Registered User
    Join Date
    08-27-2018
    Location
    London
    MS-Off Ver
    office 2016
    Posts
    45

    Re: Help Fixing Cell Range Clear Button

    Thank you for responding


    This new code works to fix the clear button but the issue of cells locking without any input reappears....for instance if the user presses delete or some other such key...the cell locks even though no input is in the cell

+ 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. Clear merged cell contents in comand button(clear all)
    By mohan_984 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2015, 10:39 AM
  2. Clear the Specific Range of Cells Using a Command Button
    By Abinaya in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2014, 05:50 AM
  3. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  4. [SOLVED] Clear button, add warning dialogue box that asks: Are you sure you want to clear?
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-21-2012, 02:41 PM
  5. Button to clear sheet and automatic clear rows
    By sandbach in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-29-2010, 02:06 PM
  6. [SOLVED] How do i clear a cell using a command button?
    By Mariann in forum Excel General
    Replies: 1
    Last Post: 03-30-2006, 04:15 PM
  7. Clear cell contents with a button
    By KFC / A&W Boy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-07-2005, 06:06 AM

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