Compilation error : BLOCK IF WITHOUT END IF

Vidush

New Member
Joined
Jan 22, 2016
Messages
3
Code:
If ((char = ",") And (cou >= 10)) Then
                        add = add + char + vbNewLine
                        c = 1
                        cou = 0
                       
                        Else
                        add = add + char
                        c = 0
                        cou = cou + 1
                
                        End If
 
Last edited by a moderator:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to the forum.

Please post the rest of the code - there is nothing wrong with the section you have posted.
 
Upvote 0
Code:
Sub VK()

    Dim i As Integer, j As Integer, ecol As String, char As String, add As String, c As Integer, sor As String, l As Integer, cou As Integer

    For i = 2 To 5000
        ecol = Cells(i, 5)
        sor = ""
        l = Len(ecol)
        c = 0
        add = ""
        cou = 0
        For j = 1 To l
            char = Mid(ecol, j, 1)
            If ((c = 1) And (char = " ")) Then
            Next j
        Else
            If ((char = ",") And (cou >= 10)) Then
                add = add + char + vbNewLine
                c = 1
                cou = 0
            Next j
        Else
            add = add + char
            c = 0
            cou = cou + 1
        Next j
    End If
End If
sor = Cells(i, 2) + vbNewLine + Cells(i, 1) + vbNewLine + add
Cells(i, 6) = sor
Next i

End Sub
 
Last edited by a moderator:
Upvote 0
Code:
Sub VK()

 Dim i As Integer, j As Integer, ecol As String, char As String, add As String, c As Integer, sor As String, l As Integer, cou As Integer

 For i = 2 To 5000
     ecol = Cells(i, 5)
         sor = ""
            l = Len(ecol)
                c = 0
                    add = ""
                     cou = 0
 For j = 1 To l
    char = Mid(ecol, j, 1)
        If ((c = 1) And (char = " ")) Then
            GoTo nextj
                Else
        If ((char = ",") And (cou >= 10)) Then
            add = add + char + vbNewLine
                c = 1
                    cou = 0
                        GoTo nextj
                Else
                  add = add + char
                    c = 0
                        cou = cou + 1
                            GoTo nextj
nextj:

  End If
 End If
 Next j
sor = Cells(i, 2) + vbNewLine + Cells(i, 1) + vbNewLine + add
Cells(i, 6) = sor
 Next i
 

 End Sub

try the above?
 
Upvote 0
You don't really need those Next j instructions, and you can't put them where you have. Try:

Code:
Sub VK()

    Dim i As Integer, j As Integer, ecol As String, char As String, add As String, c As Integer, sor As String, l As Integer, cou As Integer

    For i = 2 To 5000
        ecol = Cells(i, 5)
        sor = ""
        l = Len(ecol)
        c = 0
        add = ""
        cou = 0
        For j = 1 To l
            char = Mid(ecol, j, 1)
            If ((c = 1) And (char = " ")) Then
                ' do nothing
            Else
                If ((char = ",") And (cou >= 10)) Then
                    add = add + char + vbNewLine
                    c = 1
                    cou = 0
                End If
            Else
                add = add + char
                c = 0
                cou = cou + 1
            End If
        Next j

        sor = Cells(i, 2) + vbNewLine + Cells(i, 1) + vbNewLine + add
        Cells(i, 6) = sor
    Next i

End Sub
 
Upvote 0
It Did Work. Thanks A lot !!
But what was wrong with my code ? and what was the difference between "next j" and "GoTo nextj" ?
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top