jeudi 30 juin 2016

Multiple Checkboxes

so I have been working on this program in excel which basically runs a new command or macro to specific columns depending on which checkbox or boxes are being checked on a Userform. The problem I am running into is that I have gotten to 2 checkboxes performing a new macro when checked, thanks to some help from this site, but now I cant figure out how to get more than 2 to run a new macro or command.Any help would be great thank you! The code I have been running is like this:

     Private Sub cbs_Check()
With Me
 If .cb300Bolt And .cbSCH80 And .cbXray Then
    ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C[2])+(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[6])+(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

ElseIf .cb300Bolt And .cbSCH40 And .cbXray 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[6])+(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

                     ElseIf .cb300Bolt Then
                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[6])+(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

                   ElseIf .cbSCH80 Then
                Range("P7").Select
                ActiveCell.FormulaR1C1 = _
                "=((RC[-6]*'Sched 40 Table Data'!R[1]C)+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[4])+(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

                 ElseIf .cbXray Then
                Range("P7").Select
                 ActiveCell.FormulaR1C1 = _
                "=((RC[-6]*'Sched 40 Table Data'!R[1]C[-2])+(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

                ElseIf .cbSCH40 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

    If .cbXray And .cbSCH40 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
Sheets("SCH 40 Calculator").Select
Selection.AutoFill Destination:=Range("P7:P30"), Type:=xlFillDefault
Range("P7:P30").Select
    ElseIf .cbXray And .cbSCH80 Then
     ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C[2])+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[4])+(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

    ElseIf .cbXray And .cbCongestedArea Then
Range("P7").Select
    ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C[-2])+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[3])+(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

    ElseIf .cbXray And .cb300Bolt Then
        ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C[-2])+(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[6])+(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

    ElseIf .cb300Bolt And .cbSCH40 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[6])+(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

    ElseIf .cb300Bolt And .cbSCH80 Then
    Sheets("SCH 40 Calculator").Select
Range("P7").Select
ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C)+(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[6])+(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

   ElseIf .cbCongestedArea And .cb300Bolt Then
       Sheets("SCH 40 Calculator").Select
ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C)+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[3])+(RC[-3]*'Sched 40 Table Data'!R[1]C[-8])+(RC[-2]*'Sched 40 Table Data'!R[1]C[6])+(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

    ElseIf .cbCongestedArea And .cbSCH80 Then
ActiveCell.FormulaR1C1 = _
    "=((RC[-6]*'Sched 40 Table Data'!R[1]C)+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[5])+(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

    ElseIf .cbCongestedArea And .cbSCH40 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[3])+(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

    ElseIf .cb300Bolt And .cbSCH40 And .cbXray 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[6])+(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






           ElseIf .cbXray Then
                Range("P7").Select
                 ActiveCell.FormulaR1C1 = _
                "=((RC[-6]*'Sched 40 Table Data'!R[1]C[-2])+(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
            ElseIf .cbSCH40 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
            ElseIf .cbCongestedArea Then
                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[3])+(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

            ElseIf .cbSCH80 Then
                Range("P7").Select
                ActiveCell.FormulaR1C1 = _
                "=((RC[-6]*'Sched 40 Table Data'!R[1]C)+(RC[-5]*'Sched 40 Table Data'!R[1]C[-10])+(RC[-4]*'Sched 40 Table Data'!R[1]C[4])+(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
            ElseIf .cb300Bolt Then
                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[6])+(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 With

End Sub




Aucun commentaire:

Enregistrer un commentaire