If else end if mismatch error--"else without if"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vensriram
    New Member
    • Aug 2010
    • 48

    If else end if mismatch error--"else without if"

    Hi All,
    I am trying to write a macro with VB editor in excel. However when i try to compile my code i get an error saying "ELSE WITHOUT IF"

    My code goes like this
    Code:
            If name = name1 Then
                    If activity <> activity1 Then GoTo 10
                        If subactivity <> subactivity1 Then
                                GoTo 10
                        Else
                            GoTo 99
                        End If
                    Else
                        GoTo 99
                    End If
           End If
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. What's causing the Error is incorrect Syntax on Code Line# 2.
    2. Your Overall Logic appears to be flawed.
    3. My best guess as to what you are trying to accomplish would be:
      Code:
      If Name = name1 Then
        If activity <> activity1 Then
          If subactivity <> subactivity1 Then
            GoTo 10
          Else
            GoTo 99
          End If
        Else
          GoTo 99
        End If
      End If

    Comment

    Working...