Your first For Each loop doesn't have it's own "Next" statement,
so it's using the one from your SECOND For Each loop.
That puts the EndIf statement outside of the loop, so it stands alone.

Also, FYI...
You're Hiding UserForm1 once for each sheet in the workbook.
Once should be enough I would think.

and... is the value of "a" True/False or 0/1 ?
If it is something else, then the "If Not a then" statement will be always 
result in 'true'.. but then again, maybe that's what you want.

Make sure you indent your code so it's easier to see your loops:

Private Sub ok_Click()
>Dim a As Integer
>a = Val(text1.Text)
>If a = bp Then
>>For Each shts In ThisWorkbook.Worksheets
>>>shts.Unprotect
>>>ActiveWorkbook.Unprotect
>>>UserForm1.Hide
>>NEXT ' Missing from Your code
>End If

>If Not a Then
>>ActiveWorkbook.Protect
>>For Each shts In ThisWorkbook.Worksheets
>>>shts.Protect
>>Next
>End If

End Sub

Paul


________________________________
From: suresh k <brave.sur...@gmail.com>
To: Excel group <excel-macros@googlegroups.com>
Sent: Wednesday, March 25, 2009 11:31:01 AM
Subject: $$Excel-Macros$$ Error - "End If without block if"

Hi All,

Can anyone help on this error. Below is the code.

Private Sub ok_Click()
Dim a As Integer
a = Val(text1.Text)

If a = bp Then
For Each shts In ThisWorkbook.Worksheets
shts.Unprotect
ActiveWorkbook.Unprotect
    UserForm1.Hide
End If

If Not a Then

ActiveWorkbook.Protect
For Each shts In ThisWorkbook.Worksheets
shts.Protect
Next
End If

End Sub



--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to