+ Reply to Thread
Results 1 to 15 of 15

Cell locking

  1. #1
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Cell locking

    I have a table that users fill in. i want to force them the fill out the date in column B on the next available empty row first. all the other cells in that row are to be read only until that cell has the date in. is this possible ?

  2. #2
    Forum Contributor S O's Avatar
    Join Date
    06-25-2015
    Location
    England
    MS-Off Ver
    Office 2010 + 2013 + 2016
    Posts
    103

    Re: Cell locking

    Not actually locking the cells, but I think this does what you require, put this in the worksheet module of the sheet you want it to work on.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    ty, will look into this now

  4. #4
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    This works, but how do i modify it to use the first available row and not a random row. would i need to add Cells(Rows.Count, "B").End(xlUp) in it some how?

  5. #5
    Registered User
    Join Date
    07-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Cell locking

    To find the last used row, I would use
    Dim LastRow as Long
    Dim sw1 as WorkSheet

    Set ws1 = Sheets(mysheet) 'where mysheet is the sheetname or number of the sheet you are using
    LastRow = ws1.UsedRange.Rows.Count ' LastRow will contain the value of the last used row number

    ws1.Range("B" & LastRow).Select
    MsgBox "Enter data in cell B " & LastRow


    Insert this code, amended to suit your need into your macro.
    Last edited by mg58; 07-10-2015 at 08:41 AM.

  6. #6
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    i tried this approach now MG58, yes it locks the row and doesnt allow the entry. but the msgbox pops up with the row i am on, and not the next available row... ie if row 98 is the last row with the data in, and i try entering data on row 120, the msgbox pops up saying "To begin, enter the date in cell B120"

    I think it has to do with the used range part so i will look into changing that now
    Last edited by wayneg; 07-10-2015 at 09:09 AM.

  7. #7
    Registered User
    Join Date
    07-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Cell locking

    Oops, sorry. Should have been either:
    ws1.Range("B" & LastRow + 1).Select
    MsgBox "Enter data in cell B " & LastRow + 1

    or
    LastRow = ws1.UsedRange.Rows.Count + 1

    This will give you the next free row

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Cell locking

    Please remember to use code tags when posting code mg58?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  9. #9
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    This doesnt seem to work how i want it to, sorry......
    What i need is for it only allow input in the first available cell in column b. once there is a date in that cell, the row becomes active, and only that row.

    this information above is nearly what i need, but i keep getting msgbox saying to put date in that cell

  10. #10
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    I have added a stop function to stop the msgbox now, but it still doesnt work properly for the row its on... ie if there are 10 rows of data, and i chose row 20. the msgbox says i need to add the date in b20 and not the first free cell in column b...

    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
     
    Dim LastRow As Long
    Dim sw1 
    As Worksheet

    Set ws1 
    Sheets("Data"'where mysheet is the sheetname or number of the sheet you are using
    LastRow = ws1.UsedRange.Rows.Count ' 
    LastRow will contain the value of the last used row number

    If ws1.Range("B" LastRow) <> "" Then End

    ws1
    .Range("B" LastRow).Select
    MsgBox 
    "Enter date in cell B " LastRow




    End Sub 

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Cell locking

    Your explanation was that column B must have a date before the row can be used... are you saying it also needs to be the first blank row in column B? so if you have 10 rows of data, ONLY row 11 can be used next?

    Also, a worksheet_change is an event... that code belongs NOT in a module, but in VBA editor double-click the sheet that is affected and put the code. Then you don't need to dim the sheet, because it is implied to be THAT sheet.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Cell locking

    Try this code? Please paste it by going to VBA Editor and double-clicking the "Data" sheet on the list on left hand side. This is not code that gets put in a normal module.

    Please Login or Register  to view this content.
    Last edited by Arkadi; 07-10-2015 at 12:06 PM. Reason: UPDATED to deal with filling wrong row in col B

  13. #13
    Forum Contributor S O's Avatar
    Join Date
    06-25-2015
    Location
    England
    MS-Off Ver
    Office 2010 + 2013 + 2016
    Posts
    103

    Re: Cell locking

    Quote Originally Posted by wayneg View Post
    This works, but how do i modify it to use the first available row and not a random row. would i need to add Cells(Rows.Count, "B").End(xlUp) in it some how?
    Sorry, didn't realise you had come back on this.

    If I follow your logic I think this is what you're after:

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Cell locking

    Ty all. S O, yours worked the best... i think...lol

  15. #15
    Forum Contributor S O's Avatar
    Join Date
    06-25-2015
    Location
    England
    MS-Off Ver
    Office 2010 + 2013 + 2016
    Posts
    103

    Re: Cell locking

    Happy to help

+ 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] Locking Cells without locking worksheet
    By navialivad in forum Excel General
    Replies: 5
    Last Post: 11-24-2014, 12:44 PM
  2. Excel VBA Code for locking/unlocking a cell based on the value of another cell
    By latourjim in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-22-2013, 10:03 PM
  3. Pasting outside data into unlocked cell of protected sheet without the cell locking
    By DarthMinogue in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2011, 09:12 PM
  4. Help with macro, automatical locking cells when excel is closed but only locking 1 sh
    By snoopy1461 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2011, 11:29 AM
  5. Replies: 1
    Last Post: 07-21-2006, 11:05 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