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

Report
Posts
1
Registration date
Wednesday June 28, 2017
Status
Member
Last seen
June 28, 2017
-
 Blocked Profile -
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


You have alot of If statements, with no End if. With every If, you need an end if! Even if you use else!