+ Reply to Thread
Results 1 to 6 of 6

protecting cels based on its values possible?

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    5

    protecting cels based on its values possible?

    In column A listed are the dates. I want to protect those rows that are < the current date. I am making a ledger using excel and I don't want user to edit data which was encoded prior to the present date. Is this possible?
    Last edited by chrisumali; 12-21-2009 at 02:50 PM. Reason: to be more clear

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

    Re: protecting cels based on its values possible?

    try This,
    Sub Button1_Click()
    
        Dim r As Range
        Dim c As Range
        ActiveSheet.Unprotect
    
        Cells.Locked = False
        Set r = Range("A1", Range("A65536").End(xlUp))
    
        For Each c In r.Cells
    
            If c < Now - 1 Then
                c.EntireRow.Locked = True
            End If
    
        Next c
    
        ActiveSheet.Protect
    
    End Sub

  3. #3
    Registered User
    Join Date
    12-21-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: protecting cels based on its values possible?

    WOW it works thanks man, but if I try to insert password error prompted me. Can you please help me with this, how could I enter password in the code and no one can view that password when they go to vb editor?

    Is it possible also to run this macro upon every exit?

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

    Re: protecting cels based on its values possible?

    Sub Button1_Click()
    
        Dim r As Range
        Dim c As Range
        ActiveSheet.Unprotect Password:="Password"
    
    
        Cells.Locked = False
        Set r = Range("A1", Range("A65536").End(xlUp))
    
        For Each c In r.Cells
    
            If c < Now - 1 Then
                c.EntireRow.Locked = True
            End If
    
        Next c
    
        ActiveSheet.Protect Password:="Password"
    
    End Sub
    Check out going to VBA editor, tools,vbaProperties

  5. #5
    Registered User
    Join Date
    12-21-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: protecting cels based on its values possible?

    Thanks DAVESEXCEL!

    Ok everything is fine up to now, But one more thing. How this macro run every time user exists excel? or a macro with dialog box that will pop-up before closing saying, "You are about to exit, any entries you have made will become final and will not be edited except through authorized adjustments" then pressing ok will run the previous Macro protecting the Cell,

    Thanks Good there is you willing to give me a hand...

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

    Re: protecting cels based on its values possible?

    Quote Originally Posted by chrisumali View Post
    Thanks DAVESEXCEL!

    Ok everything is fine up to now, But one more thing. How this macro run every time user exists excel? or a macro with dialog box that will pop-up before closing saying, "You are about to exit, any entries you have made will become final and will not be edited except through authorized adjustments" then pressing ok will run the previous Macro protecting the Cell,

    Thanks Good there is you willing to give me a hand...
    This statement would not be true, if the workbook was opened again on the same day.
    You could activate the code on the workbook_open event .
    Or the
    Worksheet_selectionChange event.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim r As Range
        Dim c As Range
        ActiveSheet.Unprotect Password:="Password"
    
    
        Cells.Locked = False
        Set r = Range("A1", Range("A65536").End(xlUp))
    
        For Each c In r.Cells
    
            If c < Now - 1 Then
                c.EntireRow.Locked = True
            End If
    
        Next c
    
        ActiveSheet.Protect Password:="Password"
    
    
    End Sub
    Right click on the sheet tab and select view code, paste the code there.
    Not tested, just assuming it will work.

+ 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