+ Reply to Thread
Results 1 to 3 of 3

Type Mismatch Error when Long = 0 in For loop

  1. #1
    Registered User
    Join Date
    08-20-2014
    Location
    Denver, Colorado
    MS-Off Ver
    2010
    Posts
    18

    Type Mismatch Error when Long = 0 in For loop

    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 = False
    Dim ws As Worksheet:
    Set ws = Sheets("Sheet1")
    Dim lastrow As Long,i As Long
    Dim 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 Then
    MsgBox ("Please select a new status!")
    lblNew.ForeColor = RGB(255, 0, 0)
    bCancel = TrueEnd IfIf bCancel = True Then
    Exit Sub
    End If
    lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
    For i = 0 To LBType.ListCount - 1
    If LBType.Selected(i) Then
    ws.Range("A" & lastrow).Value = LBType.List(i)
    End If
    Next i
    For i = 0 To LBNumber.ListCount - 1 If LBNumber.Selected(i) Then
    ws.Range("B" & lastrow).Value = LBNumber.List(i) End If
    Next i
    For i = 0 To LBRotation.ListCount - 1
    If LBRotation.Selected(i) Then
    ws.Range("C" & lastrow).Value = LBRotation.List(i)
    End If
    Next x
    End Sub
    </code>

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Type Mismatch Error when Long = 0 in For loop

    Which loop is the problem with?

    PS It's square brackets for code tags.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Type Mismatch Error when Long = 0 in For loop

    Hi,

    Kindly check in the last For Loop, you are using i variable in For statement and instead of Next i you have Next x


    Regards,
    Paresh J
    Click on "* Add Reputation" as a way to say thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Help]Loop through the column to check date but i found "type mismatch" error
    By soldout2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2014, 10:23 PM
  2. [SOLVED] For Next Loop in column - type mismatch error
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-03-2013, 09:14 AM
  3. Type MisMatch error (13) with if statement using loop
    By mdnghtsnpr in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-26-2010, 10:37 AM
  4. Error 13 Type Mismatch in For Next Loop
    By VBAxellence in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-30-2009, 12:47 PM
  5. DoWhile Loop & Type mismatch error
    By oakman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2006, 06:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1