What is the syntax to see if a checkbox is checked?

 <userform name>.<checkbox name>.Value
'example
If formHome.chkActiveOnly.Value = True Then
    MsgBox "User has checked the box"
Else
    MsgBox "User has not checked the box"
End If

 

Advertisements

What is the syntax to return the index of the a listbox’s selected value?

#'i' is an integer variable that holds the index
 For i = 0 To <list box name>.ListCount - 1
     If <list box name>.Selected(i) = True Then Exit For
 Next i
#example
 For i = 0 To lstGuestList.ListCount - 1
     If lstGuestList.Selected(i) = True Then Exit For
 Next i

 

What is the syntax for Select Case?

Select Case <value>
    Case <value1>
        ‘your code here
    Case <value2>
        ‘your code here

    Case Else
        ‘your code here
End Select
‘example
Select Case userGradeInput ‘userGradeInput is an integer variable
    Case 100
        MsgBox “You got a perfect grade!”
    Case Else
        MsgBox “You did not get a perfect grade.”
End Select

 

What is the syntax to select cells?

To select a single cell

Range("<Cell Value>").Select
(ex) Range("A1").Select
(ex) Range("C3").Select

 

To select a continuous range

Range("<Cell Value>").Select
(ex) Range("A1:B4").Select
(ex) Range("C3:F400").Select

 

To select multiple non-continuous ranges

Range("<Cell Value>, <Cell Value>").Select
(ex) Range("A1:E3, H2:H44").Select
(ex) Range("C3:D4, Y3:Y4").Select

 

To select down to the 1st empty cell

Range(Selection, Selection.End(xlDown)).Select

toselectdowntofirstemptycell