Else without If Error

rehwright

New Member
Joined
Apr 27, 2018
Messages
11
Hi, I'm getting an "Else without If" Error message from the following code. The last Else is where the error points to. I have 2 If's, 2 Elses, and 2 EndIf's, so I can't figure out what the error is. Can you please help?

Code:
Sub Assign_Zero_Or_One()
Dim r As Integer
Dim n As Integer
r = -1
n = 0
Range("z3").Select
While ActiveCell.Offset(1, 0) <> 0 Or ActiveCell.Offset(1, 0) <> " "
ActiveCell.Offset(1, 0).Select
If ActiveCell = "PF" Then
ActiveCell.Offset(1, 1).Select
    While ActiveCell.Offset(1, -1) <> "T"
    n = n + ActiveCell
    r = r - 1
    ActiveCell.Offset(1, 0).Select
    Wend
        ActiveCell.Offset(r, 0).Select
    If n > 0 Then ActiveCell = 1
    Else: ActiveCell = 0
    End If
  
ActiveCell.Offset(1, -1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Wend
End Sub
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi & welcome to MrExcel.
it should be either
Code:
If n > 0 Then
   ActiveCell = 1
Else
   ActiveCell = 0
End If
or
Code:
If n > 0 Then ActiveCell = 1 Else ActiveCell = 0
You are trying to mix single line Ifs with block Ifs
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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