Hello,

I am trying to solve the following Problem. I have two ComboBoxes, both with a list of numbers from 1 to 31. One is called ComboFirst and the other is called ComboLast. I want this to happen: If I select a value in ComboFirst that is higher than ComboLast, then the value of ComboLast must change to that of ComboFIrst. If I select a number in ComboLast that is lower than ComboFirst, then the value of ComboFirst must change to the value of ComboLast. I am making sure that ComboFIrst <= ComboLast.

Which event should I use (Click, Change)? Should I use variables (e.g. FirstVal = ComboFirst.value)? Mus the variable be a variant, integer, ... ?

I am receiving a Type mismatch problem.

The following code is in Sheet1:

Private Sub ComboMonth_Change()
Sheets(1).ComboFirst.Clear
Sheets(1).ComboLast.Clear

Dim iDate As Date
Dim i As Integer

'Set to zero
i = 1
iDate = DateSerial(CInt(Range("Year")), CInt(Range("MonthNo")), i)

'Start Loop (check condition first)
Do Until Month(iDate) <> Range("MonthNo")
iDate = DateSerial(CInt(Range("Year")), CInt(Range("MonthNo")), i)
    If Month(iDate) = Range("MonthNo") Then
        With Sheets(1).ComboFirst
            .AddItem i
        End With
    
        With Sheets(1).ComboLast
            .AddItem i
        End With
    End If
i = i + 1
Loop

Sheets(1).ComboFirst.ListIndex = 0
i = Sheets(1).ComboLast.ListCount - 1
Sheets(1).ComboLast.ListIndex = i


End Sub

Private Sub ComboFirst_Click()
Dim LastVal As Integer

LastVal = Sheets(1).Range("Last")

'Make sure First <= Last
If CInt(Sheets(1).ComboFirst.Value) > LastVal Then
    Sheets(1).ComboLast.ListIndex = Sheets(1).ComboFirst.ListIndex
End If

End Sub

Private Sub ComboLast_Click()
Dim FirstVal As Integer
FirstVal = CInt(Range("First"))

'Make sure First <= Last
If CInt(Sheets(1).ComboLast.Value) < FirstVal Then
    Sheets(1).ComboFirst.ListIndex = Sheets(1).ComboLast.ListIndex
End If

End Sub
Thanks a lot!