Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:39:52+00:00 2026-06-09T12:39:52+00:00

Is it possible to lock a particular range of cells based on the input

  • 0

Is it possible to lock a particular range of cells based on the input from a dropdown in a row of data?

For example, each row of my spreadsheet represents a patient, and the first cell asks a question, to which a “Yes” or “No” response is required (which is selected/entered via a dropdown).

EDIT

The “Yes/No” cell is, in fact, a merge of two cells (G13 & H13). I have updated my example to reflect this.

EDIT ENDS

If the user selects “No”, then I wish to lock the remainder of the range of questions (G13-H13:AB13) as there is no need to enter data here. However, if the user selects, “Yes”, then the remainder of the cells shall remain available to enter data into.

All cells within each range have data entered via dropdowns only.

Here is what I am hoping to achieve:

If "No"
    Then lock range G13-H13:AB13
Else If "Yes"
    Then do nothing

i.e.

 G13-H13  I13-J13  K13-L13   ....     ....     AB13
|  NO   |  ----  |  ----  |  ----  |  ----  |  ----  |  (Locked Cells)

OR

 G13-H13  I13-J13  K13-L13   ....     ....     AB13
|  YES  |        |        |        |        |        |  (Unlocked Cells)

Once again, I would like to emphasize that all data is entered via dropdown menus and that nothing is to be typed in manually; I would like it so that if G13-H13 = "No", then the remainder of the cells within the range which have dropdowns are blocked or locked from having further information selected from their respective dropdowns.

Please note that the value in G13-H13 can be either “Yes” or “No”.

Can this be achieved using VBA and if so, how?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:39:53+00:00Added an answer on June 9, 2026 at 12:39 pm

    EDIT:
    You can do this without VBA. I based this on another answer here: https://stackoverflow.com/a/11954076/138938

    Column G has the Yes or No drop-down.

    In cell H13, set up data validation like this:

    1. Data –> Data Validation
    2. Select List in the Allow drop-down.
    3. Enter this formula in the Source field: =IF($G13="Yes", MyList, FALSE)
    4. Copy cell H13 and paste the validation (paste –> pastespecial –> validation) to cells I13:AB13.
    5. Replace MyList in the formula with the list you want to allow the user to select from for each column. Note that you’ll need to have the patient answer set to “Yes” in order to set up the validation. Once you set it up, you can delete it or set it to No.
    6. Once you have the validation set up for row 13, copy and paste the validation to all rows that need it.

    If you want to use VBA, use the following, and use the worksheet_change event or some other mechanism to trigger the LockOrUnlockPatientCells. I don’t like using worksheet_change, but it may make sense in this case.

    In order for the cells to be locked, you need to lock them and then protect the sheet. The code below does that. You need to pass it the row for the patient that is being worked on.

    Sub LockOrUnlockPatientCells(PatientRow As Long)
        Dim ws As Worksheet
        Dim YesOrNo As String
    
        Set ws = ActiveSheet
        YesOrNo = ws.Range("g" & PatientRow).Value
    
        ' unprotect the sheet so that we can modify locked settings
        ws.Unprotect
        ws.Range("a:g").Cells.Locked = False
    
        ' lock row
        Range("h" & PatientRow & ":AB" & PatientRow).Cells.Locked = True
    
        ' unlock the row depending on answer
        If YesOrNo = "Yes" Then
            Range("h" & PatientRow & ":AB" & PatientRow).Cells.Locked = False
        End If
    
        ' protect the sheet again to activate the locked cells
        ws.Protect
    
    End Sub
    

    You can test the functionality by using the following, manually adjusting the values for the patient row. Once you get it to work the way you want, get the row from the user’s input.

    Sub testLockedCells()
        Dim AnswerRow As Long
    
        AnswerRow = 9
    
        LockOrUnlockPatientCells AnswerRow
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I lock the first row and first column of a
is it possible to lock selected columns in a mysql table, example table1 with
Is it possible to lock the aspect ratio of a JFrame in Java Swing?
Possible Duplicates: Why is lock(this) {...} bad? In C# it is common to use
Possible Duplicate: How can I detect if caps lock is toggled in Swing? How
Is it possible to track the accelerometer value while under the lock screen? I
I need to know is it possible to reserve or lock money with First
Is it possible make an activity, that will lock the android device? That device
Possible Duplicate: Interface Builder Lock Item Positions? Is there a way to lock the
Possible Duplicate: Difference between lock(locker) and lock(variable_which_I_am_using) In all of the thread-safe code examples

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.