+ Reply to Thread
Results 1 to 10 of 10

VBA : Lock column after data entry

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    VBA : Lock column after data entry

    Hi everyone

    I'm trying to setup a spreadsheet where after typing in the name and selecting all the fees it would automatically lock the column
    so the user wouldnt be able to go back and change the name or the fees again after inputing them for the first time.

    So lets say i type new name in A3, I select all the fees i want to then i proceed to A4 with a different name, and at this point I should be unable to change anything in A3 but
    the program wouldn't lock me out from inputing other users in other columns until they filled.

    I found a bunch of other similar topics on that subject like :

    http://www.excelforum.com/excel-prog...ific-cell.html

    http://www.excelforum.com/excel-prog...a-entered.html

    But the only problem I have with those solutions is that they are locking down the rows as well.

    Any idea how can i lock them ?

    I've attached the spreadsheet to the post if you want to have a look

    Any help would be appreciated.

    Cheers
    Attached Files Attached Files
    Last edited by z0mg; 07-30-2013 at 01:20 PM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: VBA : Lock column after data entry

    First of all you have to make sure that all the cells in which you will be entering data are unlocked. Then you have to protect the worksheet, with or without a password. If you want to use a password, change
    ActiveSheet.Unprotect
    to
    ActiveSheet.Unprotect Password:="password"
    Do the same with
    ActiveSheet.Protect
    Change "password" to whatever password you want to use. Enter the data in each column making sure that you enter the data in column D last because entry in column D is what triggers the macro. Place this macro in the worksheet code module:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub
        ActiveSheet.Unprotect
        Target.EntireRow.Locked = True
        ActiveSheet.Protect
    End Sub

  3. #3
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: VBA : Lock column after data entry

    Thanks Mumps1! I tried to run that macro, it locking the column after the data has been inputed but its also locking the entire sheet as well rather than given column

  4. #4
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: VBA : Lock column after data entry

    I tried to play around it with again, the moment you type in anything in the D column the sheet becomes locked.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: VBA : Lock column after data entry

    You have to make sure that all the cells in the range where you will be entering data (Range("A3:D23") in your sample file) are unlocked before you run the macro. If you are still having problems, please post a copy of your actual file. It is always easier to help if we can work with the actual file. If the file contains confidential information, replace it with generic data.

  6. #6
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: VBA : Lock column after data entry

    The file was attached to the original post. I just tried it again, used the one attached to the first post, unlocked all the cells and still as long as i type anything in column D the entire sheet is protected.

  7. #7
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: VBA : Lock column after data entry

    So I looked around. I've come upon this topic http://www.excelforum.com/excel-prog...a-entered.html

    Had a go at it, it worked out just fine - once the cell got populated its getting locked.
    Another problem I have with it is that I doesn't ask for a password when click Unprotect sheet even thou the password is set in macro

    Option Explicit
    
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Range("A18:B18").Locked = False
        Selection.FormulaHidden = False
    End Sub
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="passme"
        Range("E7").Select
        ActiveSheet.Unprotect
    End Sub
    Attached Files Attached Files

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: VBA : Lock column after data entry

    Try the attached file. I'm using the file in your original post. Enter the data, colum D last and exit the cell. If you click 'Unprotect Sheet" you will be asked for a password (passme).
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-30-2013
    Location
    London UK
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: VBA : Lock column after data entry

    Thank you Mumps!

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: VBA : Lock column after data entry

    My pleasure.

+ 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. [SOLVED] to lock the cell after data entry
    By sbehera in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2013, 05:49 AM
  2. How can I lock a cell after data entry
    By sribeiro in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-02-2013, 10:21 AM
  3. lock cells after data entry
    By aleenkhan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2012, 03:14 AM
  4. [SOLVED] lock cell after data entry
    By Jim St. Martin in forum Excel General
    Replies: 1
    Last Post: 03-17-2005, 08:06 PM
  5. lock cell after data entry
    By shree58 in forum Excel General
    Replies: 0
    Last Post: 02-14-2005, 01:51 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