Forum Discussion
Getting a range of cells to act like radio buttons (True to revert to false if true in another cell)
- Oct 06, 2021
Data Validation limits what the user can enter in a cell, but it cannot change the value of a cell automatically. You need VBA for that.
Let's say the range is C2:C12.
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the code window.
Close the Visual Basic Editor.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open it.
Code:Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range If Not Intersect(Range("C2:C12"), Target) Is Nothing Then Set rng = Intersect(Range("C2:C12"), Target)(1) If rng.Value = True Then Application.ScreenUpdating = False Application.EnableEvents = False Range("C2:C12").Value = False rng.Value = True Application.EnableEvents = True Application.ScreenUpdating = True End If End If End Sub
Data Validation limits what the user can enter in a cell, but it cannot change the value of a cell automatically. You need VBA for that.
Let's say the range is C2:C12.
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the code window.
Close the Visual Basic Editor.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open it.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Not Intersect(Range("C2:C12"), Target) Is Nothing Then
Set rng = Intersect(Range("C2:C12"), Target)(1)
If rng.Value = True Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Range("C2:C12").Value = False
rng.Value = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End If
End Sub
HansVogelaar
Thank you so much!
I need multiple instances of this, and repeating the IF... to ENDIF... sections accomplished this.
Excellent!