If cell = 'YES', cell directly to the left is required

chubert

New Member
Joined
Mar 24, 2020
Messages
11
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone, need some help with how to accomplish ensuring cells are populated when required.

Whenever any cell under Column 'ANSWER' = 'YES', cell to the left (under Column 'Question') must be populated.
Directly after entering YES into the Answer column, if cell to the left is not populated, a message should appear 'Question cannot be empty if Answer = 'Yes''.

Any help greatly appreciated!

QuestionAnswer
<must be populated>YES
<does not need to be populated>NO
<must be populated>YES
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The columns we are working with are not specified in the OP, so you will need to correct them in the code if they are not columns A and B.
This is worksheet event code and must be installed in the the worksheet code module. If you already have a worksheet_change macro installed, then this will need to be merged into the existing one.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("B:B") Is Nothing Then
    If Target.Value = "Yes" And Target.Offset(, -1) = "" Then
        Application.Undo
        MsgBox "Cells under 'Question' must be populated to answer 'Yes'"", vbExclamation, "INVALID ENTRY"
   End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top