VBA compile Error: Do without Loop [Solved/Closed]

Report
Posts
1
Registration date
Wednesday June 28, 2017
Status
Member
Last seen
June 28, 2017
-
ac3mark
Posts
13029
Registration date
Monday June 3, 2013
Status
Member
Last seen
October 11, 2019
-
Hello,
So I modfied this code from an CCM post.

I have Do
I have an End IF

Why am I getting the Error?
  • This query is copying data from sheet one to four other sheets based on criteria in column C.


please help. Thank you.

Sub Metrics()

With Sheets
.Add().Name = "Bounce"
.Add().Name = "Click"
.Add().Name = "Open"
.Add().Name = "Sent"
End With


Set a = Sheets("Sheet1")
Set b = Sheets("Sent")
Set c = Sheets("Open")
Set d = Sheets("Click")
Set e = Sheets("Bounce")

Dim x
Dim z

x = 1
z = 2

Do Until IsEmpty(a.Range("C" & z))

If a.Range("C" & z) = "Sent" Then
x = x + 1
b.Rows(x).Value = a.Rows(z).Value

Else

If a.Range("C" & z) = "EmailOpen" Then
x = x + 1
c.Rows(x).Value = a.Rows(z).Value

Else

If a.Range("C" & z) = "EmailClick" Then
x = x + 1
d.Rows(x).Value = a.Rows(z).Value

Else

If a.Range("C" & z) = "Failed" Then
x = x + 1
e.Rows(x).Value = a.Rows(z).Value

Else

End If
z = z + 1

Loop

End Sub


1 reply

Posts
13029
Registration date
Monday June 3, 2013
Status
Member
Last seen
October 11, 2019
1,684
You have alot of If statements, with no End if. With every If, you need an end if! Even if you use else!