Data Validation - Two Questions

FatalLordes

New Member
Joined
Dec 22, 2017
Messages
49
Okay, I think this SHOULD be simple but I can't get my head around it.

Here is a sample table:
ABCD
1YesNoYesNo
2NoYesYesNo

So I've worked out how to get a drop down list allowing Yes or No, but my first question is how to NOT allow no answer. For example, the cell MUST contain either a Yes or No or you can't exit cell.

My second question is, using the sample table above, if an answer in a cell for Column D equals "No", then change whatever was entered on the same row but in Column A to "Yes", regardless if it was a Yes or No in there. For example, in Row 2, because No was entered in Column D, then A2 would be changed to Yes.

Hoping someone can help on either or even both questions :) Thank you in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
1) To make sure you don't have any other values than "Yes" or "No", you need to setup error message on "Error Alert" tab:
1720943514910.png
1720942738861.png

2) To make sure the cell mustn't be empty, you need a bit of VBA, since Data Validation doesn't raise error if you clear a cell. In the worksheet module you need to handle "Worksheet_Change" event:
VBA Code:
Private strVal As String

Private Sub Worksheet_Change(ByVal Target As Range)
  If Intersect([A1:D2], Target) Is Nothing Then Exit Sub
  If Target = vbNullString Then
    MsgBox "Cell cannot be empty!", vbCritical
    '// restore value
    Application.EnableEvents = False '//disable recursive events
    Target.Value = strVal
    Application.EnableEvents = True
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  '// track selection
  If Not Intersect([A1:D2], Target) Is Nothing Then
    strVal = Target.Value
  End If
End Sub
 

Attachments

  • 1720942723940.png
    1720942723940.png
    9.6 KB · Views: 2
Upvote 0
1) To make sure you don't have any other values than "Yes" or "No", you need to setup error message on "Error Alert" tab:
View attachment 114078View attachment 114077
2) To make sure the cell mustn't be empty, you need a bit of VBA, since Data Validation doesn't raise error if you clear a cell. In the worksheet module you need to handle "Worksheet_Change" event:
VBA Code:
Private strVal As String

Private Sub Worksheet_Change(ByVal Target As Range)
  If Intersect([A1:D2], Target) Is Nothing Then Exit Sub
  If Target = vbNullString Then
    MsgBox "Cell cannot be empty!", vbCritical
    '// restore value
    Application.EnableEvents = False '//disable recursive events
    Target.Value = strVal
    Application.EnableEvents = True
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  '// track selection
  If Not Intersect([A1:D2], Target) Is Nothing Then
    strVal = Target.Value
  End If
End Sub
Thanks for this. I'll give this a whirl in a couple of days time and let you know how I go! :)
 
Upvote 0
1) To make sure you don't have any other values than "Yes" or "No", you need to setup error message on "Error Alert" tab:
View attachment 114078View attachment 114077
2) To make sure the cell mustn't be empty, you need a bit of VBA, since Data Validation doesn't raise error if you clear a cell. In the worksheet module you need to handle "Worksheet_Change" event:
VBA Code:
Private strVal As String

Private Sub Worksheet_Change(ByVal Target As Range)
  If Intersect([A1:D2], Target) Is Nothing Then Exit Sub
  If Target = vbNullString Then
    MsgBox "Cell cannot be empty!", vbCritical
    '// restore value
    Application.EnableEvents = False '//disable recursive events
    Target.Value = strVal
    Application.EnableEvents = True
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  '// track selection
  If Not Intersect([A1:D2], Target) Is Nothing Then
    strVal = Target.Value
  End If
End Sub
Hi

I tried doing the error validation in response to my first question, but it is not working. I'm using Excel on the Web (within OneDrive), so not sure if there are limitations to that? Basically, I tried with the "Ignore Blank" ticked and not ticked, and completed Error as shown, but it still lets me tab past a blank cell:
1721018548886.png

1721018581764.png
 
Upvote 0
Oh, you should've mentioned Web version beforehand. Of course, in Web you cannot use VBA code.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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