Share via

EXCEL 2010 - Locking Cells based on Cell Value

Anonymous
2014-03-04T21:17:53+00:00

Here is a basic set-up that I am trying to acheive:

Column A has a validation list for "Yes" or "No" only.

Column B will have data entered ONLY IF Column A has a value of "No".

Is there a way to prevent data entry to a cell in Column B if the neighbor cell in Column A has a value of "Yes"?

This would be the preferred method.

A second solution would be to Conditionally Format Column B with a data entry based on the Column A value of "Yes".

A third solution would be to Conditionally Format Column B with a Color fill based on the Column A value of "Yes".

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2014-03-12T21:29:11+00:00

    Well, this worked... but only for my worksheet.  Since this is a shared doc, it did not work for any of the others in the worksheet as well.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-03-05T00:21:26+00:00

    Hi,

    The correct changes for Col F & G are this

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

     If Not Intersect(Target, Columns(7)) Is Nothing Then

     If UCase(Cells(Target.Row, "F")) = "YES" Then

     Application.EnableEvents = False

     MsgBox "Range G" & Target.Row & " is locked"

     Cells(Target.Row, "H").Select

     Application.EnableEvents = True

     End If

     End If

     End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-03-04T22:37:29+00:00

    So, the columns that I am actually needing this are F & G as opposed to A & B.

    I copied and pasted the code and changed, what I believe to be, A & B accordingly as below:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Intersect(Target, Columns(2)) Is Nothing Then

    If UCase(Cells(Target.Row, "F")) = "YES" Then

    Application.EnableEvents = False

    MsgBox "Range G" & Target.Row & " is locked"

    Cells(Target.Row, "H").Select

    Application.EnableEvents = True

    End If

    End If

    End Sub

    The error I receive is "Compile Error: End If without block If"

    Thoughts?

    Also, can macro enabled worksheets be shared worksheet?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-03-04T21:31:11+00:00

    Hi,

    Right click your sheet tab, view code and paste this code in on the right. Close VB editor and try selecting any cell in Col B where there is a Yes in the same row of Col A.

    You will need to save your workbook as macro enabled with a .xlsm extenstion

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

     If Not Intersect(Target, Columns(2)) Is Nothing Then

     If UCase(Cells(Target.Row, "A")) = "YES" Then

     Application.EnableEvents = False

     MsgBox "Range B" & Target.Row & " is locked"

     Cells(Target.Row, "C").Select

     Application.EnableEvents = True

     End If

     End If

     End Sub

    Was this answer helpful?

    0 comments No comments