0
    Dim i, y, x As Integer
    i = 1

    Do Until Cells(i, 2) Like "L E G E N D :"
        y = 1
        x = 0

        If Cells(i, 2) Like "   *" And Cells(i, 3) = "ALL MEDIA" Then
            Do Until Cells(y, 2) Like "L E G E N D :"
                If Cells(i, 2) = Cells(y, 2) Then x = x + Cells(y, 4)
                y = y + 1
                Cells(i, 4) = x
            Loop

            i = i + 1

    Loop
End Sub

I just have two loops there and I have an error

Loop without Do

and I clearly can see that I have this Loop and Do 2x :D

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
endrew
  • 117
  • 6
  • 7
    You're missing an `End If`. – BigBen Mar 31 '20 at 12:39
  • 4
    And note that `Dim i, y, x As Integer` will only declare `x` as `Integer` but the others as `Variant`. You need to specify a type for **every** variable in VBA: `Dim i As Long, y As Long, x As Long`. Since Excel has more rows than `Integer` can handle you need to use `Long`. • I actually recommend [always to use Long instead of Integer](https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long/26409520#26409520) as there is no benefit in using `Integer` in VBA. – Pᴇʜ Mar 31 '20 at 12:41
  • 4
    Indenting the code correctly makes your mistake visible immediately (I did that for you in your question). While formatting code nicely might at first seem to be cumbersome and unnecessary it comes with a huge benefit: Find your mistakes more easily and save a lot of time. – Pᴇʜ Mar 31 '20 at 12:45
  • BTW, as a shot in the dark, you might need to move `x = 0` before the start of the 2nd loop – HTH Mar 31 '20 at 12:46
  • 3
    and it seems `= "L E G E N D :"` would do instead of `Like "L E G E N D :"` – HTH Mar 31 '20 at 12:48

0 Answers0