Consulting

Results 1 to 9 of 9

Thread: Solved: Inserting data into the column and maintain it locked

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Solved: Inserting data into the column and maintain it locked

    Hi.
    how can I insert data in column 'A' and keep it locked automatically?
    the code below to insert the data in column 'A' I need mater ONLY column A locked, but this should be done automatically because kok code vai desbloque it to enter data.
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, 1).Value = Date
    End Sub[/VBA]

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Like this:[VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, 1).Value = Date
    Target.Locked = True
    Activesheet.Protect Password:="password"
    End Sub
    [/VBA]But you will need to make sure all other cells are unlocked otherwise the whole sheet will be protected!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    I need only the column 'A' is blocked!

    thank you

  4. #4
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    HI my frends

    Any ideas?

    Thank you!!!

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Then change target column to 1!!!!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    I changed but all cells are locked!

    I need only column A is locked, after inserting the data into it.

    My code is:
    when typing in B2, enter data in A2
    when typing in B3, enter data in A3
    when typing in B4, A4 insert data in
    and so on.
    what I need is:
    when typing in B2, enter data in A2, which is locked.
    unlocks for typing in B3, enter data in A3, which is locked.
    unlocks for typing in B4, A4 insert data that is locked.
    and so on.

  7. #7
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi my frends

    Any ideas?

    Thank you!!!

  8. #8
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Marreco,

    Set up the sheet with this code (before protecting it):

    [vba]Sub sheetSetUp()
    Cells.Locked = False
    Columns(1).Locked = True
    End Sub[/vba]
    Then use this in the sheet code container:
    [vba]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then
    ActiveSheet.Unprotect Password:="password"
    Cells(Target.Row, 1).Value = Date
    ActiveSheet.Protect Password:="password"
    End If
    End Sub[/vba]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  9. #9
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    I'm very glad you helped me!
    solved my problem so splendid!!
    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •