dmqueen
Board Regular
- Joined
- Aug 5, 2014
- Messages
- 53
Good Morning,I am receiving a type mismatch error I cannot resolve. Any help would be greatly appreciated.
It occurs when it enters a For loop for the last control, when the loop control = 0. Code below:I even tried recasting as a Variant, but it didn't help. I have marked the line with an asterisked comment.<code>Private Sub EnterButton_Click()Dim bCancel As Boolean: bCancel = FalseDim ws As Worksheet: Set ws = Sheets("Sheet1")Dim lastrow As Long,i As LongDim x As Long'''''''''''''''''''''''''''' Check for no selections'''''''''''''''''''''''''''If LBType.ListIndex = -1 Then MsgBox ("You must select a type!") bCancel = True LblType.ForeColor = RGB(255, 0, 0) ElseIf LBNumber.ListIndex = -1 Then MsgBox ("You must select a number!") LblNumber.ForeColor = RGB(255, 0, 0) bCancel = True ElseIf LBRotation.ListIndex = -1 Then MsgBox ("You must select a rotation!") LblRotation.ForeColor = RGB(255, 0, 0) bCancel = True ElseIf cmbNew.ListIndex = False ThenMsgBox ("Please select a new status!")lblNew.ForeColor = RGB(255, 0, 0)bCancel = TrueEnd IfIf bCancel = True Then Exit SubEnd Iflastrow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1For i = 0 To LBType.ListCount - 1 If LBType.Selected(i) Then ws.Range("A" & lastrow).Value = LBType.List(i) End IfNext iFor i = 0 To LBNumber.ListCount - 1 If LBNumber.Selected(i) Then ws.Range("B" & lastrow).Value = LBNumber.List(i) End IfNext iFor i = 0 To LBRotation.ListCount - 1 If LBRotation.Selected(i) Then ws.Range("C" & lastrow).Value = LBRotation.List(i) End IfNext i'The error occurs on the next line!*************************************************************************For x = 0 To cmbNew.ListCount - 1 If cmbNew.ListIndex(x) Then ws.Range("D" & lastrow).Value = cmbNew.ListIndex(x) End If Next xEnd Sub</code>
