dimanche 15 avril 2018

Having a VBA Checkbox add a value to a cell on a different sheet

First off, I have absolutely no experience with coding VBA. I've managed to scrounge up a few bits of code to add in a checkbox on Excel, which works fine, but I want to have my calculations on a second sheet that I can hide. I need two checkboxes which are mutually exclusive, only one can be checked at a time, or both left unchecked. When either box is ticked, I need them to put a value in a cell on Sheet 2. So far I have -

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then Range("F22").Value = -1190
If CheckBox1.Value = False Then Range("F22").Value = 0
End Sub

Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then Range("G22").Value = 1190
1190
If CheckBox2.Value = False Then Range("G22").Value = 0
End Sub

I obviously need the change the "F22" and "G22" to be the respective cells on the second sheet, but I've tried adding "Sheet2!" in a variety of ways with no success.

(Everything else is working fine, I just don't want to have those cells on the same sheet, so I can keep them locked away.)

Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire