Selasa, 19 Mei 2015

Pencabangan 2 : Select Case

Sub Sheet2_RoundedRectangle1_Click()
ActiveCell.Offset(0, -1).Select
Nilai = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
If Nilai = 0 Then
    ActiveCell.Value = "Nol"
Else
    If Nilai = 1 Then
        ActiveCell.Value = "Satu"

    Else
        If Nilai = 2 Then
            ActiveCell.Value = "Dua"
        Else
            If Nilai = 3 Then
                ActiveCell.Value = "Tiga"
            Else
                ActiveCell.Value = "Error"
            End If
        End If
    End If
End If
ActiveCell.Offset(1, 0).Select
End Sub

================= Select Case =====================

Sub RoundedRectangle2_Click()

    ActiveCell.Offset(0, -1).Select
    Nilai = ActiveCell.Value
    ActiveCell.Offset(0, 1).Select

    Select Case Nilai
    Case 0: ActiveCell.Value = "Nol"
    Case 1: ActiveCell.Value = "Satu"
    Case 2: ActiveCell.Value = "Dua"
    Case 3: ActiveCell.Value = "Tiga"
    Case Else
        ActiveCell.Value = "Error"
    End Select
    ActiveCell.Offset(1, 0).Select

End Sub

Tidak ada komentar:

Posting Komentar