lundi 27 juin 2016

Using IF & AND statements with Checkboxes on a Userform

A little background: I have so far created a userform with checkboxes that each run separate macros initially then when unchecked they run an identical macro to return to the "normal" state. This was done using an IF, Else statement.

My question is how to combine the If statement with an AND statement so when/if two boxes are checked they run a different code or macro.

I am still very new to VBA and coding but it seems like a rather simple idea to me as I got the IF else statement to work. But for some reason the code I have been trying hasn't been working and I dont recieve any errors it just doesn't do anything when I have both boxes checked.

The code I have been trying is:

Private Sub cbXray_Click()

If cbXray.Value = True And cbSCH40.Value = True Then
 ActiveCell.FormulaR1C1 = _
        "=((RC[-6]*'Sched 40 Table Data'!R[1]C[1])+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[-9])+(RC[-3]*'Sched 40 Table Data'!R[1]C[-8])+(RC[-2]*'Sched 40 Table Data'!R[1]C[-7])+(RC[-1]*'Sched 40 Table Data'!R[1]C[-6]))"
Range("P7").Select
Selection.AutoFill Destination:=Range("P7:P30"), Type:=xlFillDefault
Range("P7:P30").Select

Else

Range("P7").Select
ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C[-11])+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[-9])+(RC[-3]*'Sched 40 Table Data'!R[1]C[-8])+(RC[-2]*'Sched 40 Table Data'!R[1]C[-7])+(RC[-1]*'Sched 40 Table Data'!R[1]C[-6]))"
Range("P7").Select
Selection.AutoFill Destination:=Range("P7:P30"), Type:=xlFillDefault
Range("P7:P30").Select
End If


End Sub

Thank you in advance!




Aucun commentaire:

Enregistrer un commentaire