当语句符合标准时如何停止循环? -vba,Excel中

时间:2016-12-04 06:15:08

标签: vba excel-vba loops excel

Private Sub CommandButton1_Click()

Dim Year             As Long
Dim i As Long

Year = 2008
For Year = 2008 To ComboBox2.Value
    For i = 2 To 200 Step 12
        If ComboBox1.Value = "Januari" Then
            Range("G15").Value = Sheets(3).Cells(i, 1).Value
         ElseIf ComboBox1.Value = "Februari" Then
            Range("G15").Value = Sheets(3).Cells(i + 1, 1).Value
         ElseIf ComboBox1.Value = "Maret" Then
            Range("G15").Value = Sheets(3).Cells(i + 2, 1).Value
         ElseIf ComboBox1.Value = "April" Then
            Range("G15").Value = Sheets(3).Cells(i + 3, 1).Value
         ElseIf ComboBox1.Value = "Mei" Then
            Range("G15").Value = Sheets(3).Cells(i + 4, 1).Value
         ElseIf ComboBox1.Value = "Juni" Then
            Range("G15").Value = Sheets(3).Cells(i + 5, 1).Value
         ElseIf ComboBox1.Value = "Juli" Then
            Range("G15").Value = Sheets(3).Cells(i + 6, 1).Value
         ElseIf ComboBox1.Value = "Agustus" Then
            Range("G15").Value = Sheets(3).Cells(i + 7, 1).Value
         ElseIf ComboBox1.Value = "September" Then
            Range("G15").Value = Sheets(3).Cells(i + 8, 1).Value
         ElseIf ComboBox1.Value = "Oktober" Then
            Range("G15").Value = Sheets(3).Cells(i + 9, 1).Value
         ElseIf ComboBox1.Value = "November" Then
            Range("G15").Value = Sheets(3).Cells(i + 10, 1).Value
         ElseIf ComboBox1.Value = "Desember" Then
            Range("G15").Value = Sheets(3).Cells(i + 12, 1).Value
         End If
    Next i

Next Year

Sheets(2).Range("I5").Value = ("CONTRACT SPOT")

End Sub

我想要它当我选择januari 2009组合它显示1,我选择januari 2010组合它显示13等等。请帮忙

0 个答案:

没有答案