• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Allow Only One Checkbox True

Status
Not open for further replies.

BillyRay

New Member
Hello,

I have checkboxes (True/False type) for Low, Medium, or High Priority. Is there a way with VBA to only allow one checkbox true?

Columns G, H, and I have the checkboxes.

Thank you for help
 

Attachments

  • Tasks.xlsm
    532.3 KB · Views: 5
Another way in the attached.
Will work on the columns headed L, M & H, even if they are not next to each other.
Only selecting a cell will not add a tick
When revisiting a row to uncheck a box, it will not need to be clicked twice.

Downsides:
Can be tricked by setting a group of cells to true in one go (it only handles single cell changes).
Will fall over if any of the columns L, M & H are missing.

I'm guessing that you may have more than one sheet that you need this to work on?
If so, instead of having this code in each sheet, similar code could be in the ThisWorkbook code-module. Come back if that's the case.

The code in the attached workbook:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
  On Error Resume Next
  Set tbl = Target.ListObject
  On Error GoTo 0
  If Not tbl Is Nothing Then
    With tbl
      Set rngCBoxColms = Union(.ListColumns("L").DataBodyRange, .ListColumns("M").DataBodyRange, .ListColumns("H").DataBodyRange)
      If Not Intersect(rngCBoxColms, Target) Is Nothing Then
        Set rngLMH = Intersect(Target.EntireRow, rngCBoxColms)
        If Target Then                           'only operates if a tick is being added to the checkbox (ie. from false to true)
          For Each cll In rngLMH.Cells
            If cll.Address <> Target.Address Then cll.Value = False
          Next cll
        End If
      End If
    End With
  End If
End If
End Sub
 

Attachments

  • Chandoo57803Tasks.xlsm
    546 KB · Views: 2
Last edited:
Conversation continued in separate thread:
 
Status
Not open for further replies.
Back
Top