Code based on condition of a Checkbox

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have a checkbox1 I only want the code to run of the box is checked. (And have a message box if its not checked.) How do I put that If statement in?

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
    Dim LastRow As Long
'
        LastRow = ActiveWorkbook.ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
'
        Range("D9:D" & LastRow).FormulaR1C1 = _
        "=IFERROR((IF(R[1]C[-1]>RC[-1],""Parent"",""Child"")),"""")"
        Range("D9:D" & LastRow).Value = Range("D9:D" & LastRow).Value
        
        Range("K8:K" & LastRow).FormulaR1C1 = _
        "=IFERROR(((YEAR(RC[-1])-YEAR(RC[-2]))*12+MONTH(RC[-1])-MONTH(RC[-2])),"""")"
    
        Range("L8:L" & LastRow).FormulaR1C1 = _
        "=IFERROR((IF(RC[-3]<>"""",(IFERROR((MONTH(RC[-3])-MONTH(R2C[-8])+1+(YEAR(RC[-3])-YEAR(R2C[-8]))*12),"""")),"""")),"""")"
    
        Range("M8:M" & LastRow).FormulaR1C1 = _
        "=IF(AND(RC[-3]<>"""",R[-6]C[-9]<>""""),(MONTH(RC[-3])-MONTH(R2C[-9])+1+(YEAR(RC[-3])-YEAR(R2C[-9]))*12),"""")"
        
        Range("K8:M" & LastRow).Value = Range("K8:M" & LastRow).Value
'
'       Range("B" & LastRow + 1).Select

    Dim Ind As Range
        For Each Ind In Range("C8", Range("C" & Rows.Count).End(xlUp))
            Union(Ind.Offset(, -1), Ind.Offset(, 2)).IndentLevel = Ind.Value
    Next Ind
'
Sheets("Work Breakdown Structure").Protect
End Sub
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Got it

If CheckBox1.Value = False Then
WBS_Tab_Formatting
Else
End If

I named the code above "WBS_Tab_Formatting"
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top