$$Excel-Macros$$ Re: Error - "End If without block if"

2009-03-27 Thread suresh k
Thanks Ajay, This code is working fine. But when I enter some text in this field Iam getting error. Please provide me the solution. On 3/26/09, Ajay Varshney wrote: > > Use this code: > > Private Sub CommandButton1_Click() > Dim A As Integer > Dim Shts As Worksheet > A = TextBox1.Value > If A = 1

$$Excel-Macros$$ Re: Error - "End If without block if"

2009-03-26 Thread Ajay Varshney
Use this code: Private Sub CommandButton1_Click() Dim A As Integer Dim Shts As Worksheet A = TextBox1.Value If A = 123 Then For Each Shts In ThisWorkbook.Worksheets Shts.Unprotect Password:=123 Next UserForm1.Hide Else For Each Shts In ThisWorkbook.Worksheets Shts.Protect Password:=123 Next UserFo

$$Excel-Macros$$ Re: Error - "End If without block if"

2009-03-25 Thread Paul Schreiner
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 thin