+ Reply to Thread
Results 1 to 6 of 6

If cell = value, lock nearby range

  1. #1
    Registered User
    Join Date
    08-25-2016
    Location
    California
    MS-Off Ver
    2007
    Posts
    3

    If cell = value, lock nearby range

    I'm having an issue with this code and I can't figure it out.

    The goal is to look in cells A1:A5 for "lock" or "unlock". Based on the value, I want to lock/unlock the corresponding row (say cell a4 = "lock", then row 4 is locked... cell a5 = "unlock" row 5 is unlocked).

    Any help is greatly appreciated.

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

    Re: If cell = value, lock nearby range

    I don't see a code

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If cell = value, lock nearby range

    probably overkill for such a small data set, but if your set was significantly larger, it would be better than a loop.

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  4. #4
    Registered User
    Join Date
    08-25-2016
    Location
    California
    MS-Off Ver
    2007
    Posts
    3

    Re: If cell = value, lock nearby range

    Quote Originally Posted by davesexcel View Post
    I don't see a code
    Sorry I didn't supply one.

    Quote Originally Posted by walruseggman View Post
    probably overkill for such a small data set, but if your set was significantly larger, it would be better than a loop.

    Please Login or Register  to view this content.
    I tried this but it didn't work. The actual range is dynamic depending on another factor. The A1:A5 is just an example of the potential 200-300 rows.

  5. #5
    Registered User
    Join Date
    08-25-2016
    Location
    California
    MS-Off Ver
    2007
    Posts
    3

    Re: If cell = value, lock nearby range

    I just needed to protect it after.

    Thank you so much for your help! I changed it slightly for columns (using them both I can dynamically control what end users will access).

    Sub LockColumns()
    Set r = Worksheets("Summary-Expenditures").Range("a1:zz100")
    r.AutoFilter Field:=1, Criteria1:="lock"
    r.SpecialCells(12).EntireRow.Locked = True
    r.AutoFilter Field:=1, Criteria1:="unlock"
    r.SpecialCells(12).EntireRow.Locked = False
    r.AutoFilter
    Worksheets("Summary-Expenditures").Protect
    End Sub

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If cell = value, lock nearby range

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Search for value in column A, then identify rows from range of nearby cells, then copy
    By hadamhiram in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 09:46 AM
  2. Search for word then add value in a cell nearby
    By Biffinator in forum Excel General
    Replies: 4
    Last Post: 01-30-2015, 10:51 AM
  3. Sum cells along a row based on nearby cell values using a formula
    By mwhelan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-24-2014, 04:49 AM
  4. Priavte sub to move chart nearby active cell in column B
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2014, 04:45 PM
  5. [SOLVED] Delete a range of nearby rows where a cell = 0 (and loop to catch all)
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 08:09 PM
  6. Select from list then populate nearby cell? Possible?
    By xMergatroid2x in forum Excel General
    Replies: 5
    Last Post: 06-15-2012, 01:46 PM
  7. Conditional Formatting - Grey Out and Lock A range based on a cell value in that range
    By Excelgnome in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2012, 07:31 PM

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