Print Numbers based on Check box

     

  • It denotes about TRUE\FALSE
  •  

    If Checkbox1.value = true then ...Condition

     

  • Print numbers based on status of CHECK BOX
  •  

    Private Sub CommandButton1_Click()
    Columns(1).Clear
    Dim j As Integer
    If CheckBox1.Value = True Then j = 5
    If CheckBox1.Value = Flase Then j = 10
    Dim i As Integer
    For i = 1 To j
    Cells(i, 1).Value = i
    Next
    End Sub

    Download the Workbook

     

    Checkbox True\False Value

     

    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then Range("A1").Value = "First"
    If CheckBox1.Value = False Then Range("B1").Value = "Second"
    If CheckBox1.Value = False Then Range("A1").Value = ""
    If CheckBox1.Value = True Then Range("B1").Value = ""
    End Sub

     

    Download The Workbook

     

    Two check boxes

     

    Private Sub CommandButton1_Click()
    Columns(1).Clear
    Dim j As Integer
    If CheckBox1.Value = True And CheckBox2.Value = False Then
    j = 10
    ElseIf CheckBox1.Value = False And CheckBox2.Value = True Then
    j = 5
    Else
    j = 15
    End If
    For i = 1 To j
    Cells(i, 1).Value = i
    Next
    End Sub

     

    Download The Workbook

     

    Two check boxes - Example

     

     

    Private Sub CommandButton1_Click()
    ActiveSheet.UsedRange.Clear
    With Me
    If CheckBox1.Value = True And CheckBox2.Value = False Then
    Range("A1:A15").Value = "Firstbox Selected"
    ElseIf CheckBox1.Value = False And CheckBox2.Value = True Then
    Range("B1:B15").Value = "Second Selected"
    ElseIf CheckBox1.Value = True And CheckBox2.Value = True Then
    Range("C1:C15").Value = "Both are Selected"
    Call num
    End If
    ActiveSheet.UsedRange.Columns.AutoFit
    End With
    End Sub

    Download The Workbook