Compile error

E

Ed

When I run the following macro:

--------------------------------------------------------------------------

For r = 2 To 50
For c = 4 To 50



If Cells(r, 4) = "" Then Cells(r, 2) = 0
End If

If Cells(r, c) > 0 And Cells(r, c + 1) = "" Then Cells(r, 2) = c - 3

End If
Next
Next

------------------------------------------------------------------

I get the following message:

------------------------------------------------------------------------

Compile error

End if without block if


OK Help
-----------------------------------------------------

How do I correct the macro?

Would appreciate any help


EJE
 
D

Dave Patrick

Remove "End If" in both places.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| When I run the following macro:
|
| --------------------------------------------------------------------------
|
| For r = 2 To 50
| For c = 4 To 50
|
|
|
| If Cells(r, 4) = "" Then Cells(r, 2) = 0
| End If
|
| If Cells(r, c) > 0 And Cells(r, c + 1) = "" Then Cells(r, 2) = c - 3
|
| End If
| Next
| Next
|
| ------------------------------------------------------------------
|
| I get the following message:
|
| ------------------------------------------------------------------------
|
| Compile error
|
| End if without block if
|
|
| OK Help
| -----------------------------------------------------
|
| How do I correct the macro?
|
| Would appreciate any help
|
|
| EJE
 
I

Ivan Raiminius

Hi Eje,

For r = 2 To 50
For c = 4 To 50

If Cells(r, 4) = "" Then Cells(r, 2) = 0
If Cells(r, c) > 0 And Cells(r, c + 1) = "" Then Cells(r, 2) = c - 3
Next
Next

or

For r = 2 To 50
For c = 4 To 50

If Cells(r, 4) = "" Then
Cells(r, 2) = 0
End If

If Cells(r, c) > 0 And Cells(r, c + 1) = "" Then
Cells(r, 2) = c - 3
End If
Next
Next

Regards,
Ivan
 
I

Ikaabod

You can remove the "End If" statements since you put the "Then"
statement on the same line as the "If". Like this:
For r = 2 To 50
For c = 4 To 50
If Cells(r, 4) = "" Then Cells(r, 2) = 0
If Cells(r, c) > 0 And Cells(r, c + 1) = "" Then Cells(r, 2) = c - 3
Next
Next

If you want to use the "end if" it'd look like this:
If Cells(r, 4) = "" Then
Cells(r, 2) = 0
End If
 
N

Norman Jones

Hi Ed,
If Cells(r, 4) = "" Then Cells(r, 2) = 0
End If


Try

If Cells(r, 4) = "" Then Cells(r, 2) = 0 End If

or

If Cells(r, 4) = "" Then
Cells(r, 2) = 0
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top