You've nested the Ifs within each other so the second one is tested only if the first one is true (and if that's true, the second one can't be). You can either use:
Private Sub Machine_Change()
'Variable Declaration
Dim iRow As Integer
iRow = 1
'Clear Combobox2 before loading items
PGNumber.Text = ""
If Me.Demand.Value = "This month" Then
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 7)
ElseIf Me.Demand.Value = "next month" Then
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 8)
ElseIf Me.Demand.Value = "next 3 month" Then
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 9)
End If
End Sub
or use a Select Case construction:
Private Sub Machine_Change()
'Variable Declaration
Dim iRow As Integer
iRow = 1
'Clear Combobox2 before loading items
PGNumber.Text = ""
Select Case Me.Demand.Value
Case "This month"
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 7)
Case "next month"
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 8)
Case "next 3 month"
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, 9)
End Select
End Sub
Since the loop code is the same other than the column number, you could simplify to:
Private Sub Machine_Change()
'Variable Declaration
Dim iRow As Long
Dim colNum as Long
iRow = 1
'Clear Combobox2 before loading items
PGNumber.Text = ""
Select Case Me.Demand.Value
Case "This month"
colNum = 7
Case "next month"
colNum = 8
Case "next 3 month"
colNum = 9
End Select
If colNum <> 0 then
Do
iRow = iRow + 1
Loop Until Machine.Text = Sheets("ADDNEW").Cells(iRow, 6)
PGNumber.Text = Sheets("ADDNEW").Cells(iRow, colNum)
end if
End Sub
Bookmarks