Forum Discussion
EMBBerwyn
May 06, 2022Copper Contributor
2 Data Validation Queries and Students Changing Their Minds
I have a two cells using data validation. A1 Question “Are you an Economics major ?” Data Validation List “Yes/No” A2 Question “Are you enrolled in Money & Banki...
- May 06, 2022
Right-click the sheet tab.
Select 'View code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A1"), Target) Is Nothing Then If Range("A1").Value <> "Yes" Then Application.EnableEvents = False Range("A2").ClearContents Application.EnableEvents = True End If End If End SubSwitch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Students will have to allow macros when they open the workbook.
Sample workbook attached.
HansVogelaar
May 06, 2022MVP
Right-click the sheet tab.
Select 'View code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A1"), Target) Is Nothing Then
If Range("A1").Value <> "Yes" Then
Application.EnableEvents = False
Range("A2").ClearContents
Application.EnableEvents = True
End If
End If
End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Students will have to allow macros when they open the workbook.
Sample workbook attached.
EMBBerwyn
May 09, 2022Copper Contributor
Hans,
I've run into a problem, students are answering "Yes" to both questions and then changing their major while leaving the Money & Banking answer as "Yes," since seats are limited how can I hide both the second question and the data validation box if or when they change their majors?
Thanks,
I've run into a problem, students are answering "Yes" to both questions and then changing their major while leaving the Money & Banking answer as "Yes," since seats are limited how can I hide both the second question and the data validation box if or when they change their majors?
Thanks,
- HansVogelaarMay 09, 2022MVP
If a student changes A1 to "No" or clears A1, the code should automatically clear A2. But it's easy to hide row 2 - see the attached version.