+ Reply to Thread
Results 1 to 4 of 4

Locking a cell after you click it?

Hybrid View

  1. #1
    Registered User
    Join Date
    12-08-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Locking a cell after you click it?

    Hi,

    I am using the following formula below, to enter the current date in excel once you click a cell within the range. Is it possible, once you click the cell and the date is entered automatically to lock the cell with a password so it can not be edited?
    Formula is as follows: (thanks to TOM1977)

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myrange As Range
    Set myrange = Union(Range("A1:A10"), Range("C1:C10"))
    If Not Intersect(Target, myrange) Is Nothing Then
    Target = Format(Now, "dd/mm/yyyy")
    End If
    End Sub

    Thanks

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Locking a cell after you click it?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    12-08-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Locking a cell after you click it?

    Hi,

    Sorry Mordred.... New Here.

    I am using the following formula below, to enter the current date in excel once you click a cell within the range. Is it possible, once you click the cell and the date is entered automatically to lock the cell with a password so it can not be edited?
    Formula is as follows: (thanks to TOM1977)

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myrange As Range
    Set myrange = Union(Range("A1:A10"), Range("C1:C10"))
    If Not Intersect(Target, myrange) Is Nothing Then
    Target = Format(Now, "dd/mm/yyyy")
    End If
    End Sub
    Thanks

  4. #4
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Locking a cell after you click it?

    How about just putting a validation-rule on it; - making the exact text the only possible option?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myrange As Range
    Set myrange = Union(Range("A1:A10"), Range("C1:C10"))
    If Not Intersect(Target, myrange) Is Nothing Then
    Target = Format(Now, "dd/mm/yyyy")
    'altered:
    Target.Validation.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=Target.Value
    End If
    End Sub
    _______________________________________________
    Remember:

    Read the rules!

    Use code tags! Place [CODE] before the first line of code and [/CODE] after the last line of code.

    Mark your post [SOLVED] if it has been answered satisfactorily.
    To do this, click EDIT in your original post, click GO ADVANCED and set the PREFIX. It helps everybody!

    If you are approve (or disapprove) of any members response to your problem, please click the star icon underneath their post and comment. It matters.

+ 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