jeudi 23 juillet 2020

Use VBA code for enabling checkboxes on multiple rows

I have a spreadsheet that has 3 checkbox options for each row, I have created a VBA to disable the other 2 checkboxes once a checkbox is created (so that only 1 checkbox can be checked), however my solution only works for one row and I need some help in rewriting this so that it will apply to all rows please. (I'm new to VBA).

The code I have used is this:

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
  CheckBox2.Value = False
  CheckBox2.Enabled = False
  CheckBox3.Value = False
  CheckBox3.Enabled = False
Else
  CheckBox2.Value = False
  CheckBox2.Enabled = True
  CheckBox3.Value = False
  CheckBox3.Enabled = True
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
  CheckBox1.Value = False
  CheckBox1.Enabled = False
  CheckBox3.Value = False
  CheckBox3.Enabled = False
Else
  CheckBox1.Value = False
  CheckBox1.Enabled = True
  CheckBox3.Value = False
  CheckBox3.Enabled = True
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox3.Value = True Then
  CheckBox1.Value = False
  CheckBox1.Enabled = False
  CheckBox2.Value = False
  CheckBox2.Enabled = False
Else
  CheckBox1.Value = False
  CheckBox1.Enabled = True
  CheckBox2.Value = False
  CheckBox2.Enabled = True
End If
End Sub



Aucun commentaire:

Enregistrer un commentaire