Thread
:
End if w/o if?
View Single Post
#
9
Posted to microsoft.public.excel.programming
Don Guillett[_4_]
external usenet poster
Posts: 2,337
End if w/o if?
I use single line ifs much of the time
--
Don Guillett
SalesAid Software
"Toppers" wrote in message
...
Agreed!
"Bob Phillips" wrote:
I see your point. As I say, you should indent Ifs, and don't use single
line
Ifs, it all gets too confusing.
Bob
"Toppers" wrote in message
...
But it could be End If to If Not TopCell Is Nothing which admittedly
could
come before If .name as per Don's reply. Both are valid I think.
"Bob Phillips" wrote:
No, he has a line continuation, so no End If needed.
--
HTH
Bob Phillips
"Toppers" wrote in message
...
Hi,
If .Name Like "*[##]" Then _
.Name = Left(.Name, Len(.Name) - 2)
End If ...... Missing here
HTh
"davegb" wrote:
I've combined 2 macros that I got help writing here.
Sub AllSheetsToggleProtectWInd()
'for all sheets in currently active workbook, assigned to
button
Dim TopCell As Range
Dim TopCol As Range
Dim Cols2Hide As Range
Dim wkSht As Worksheet
For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
If .ProtectContents Then
.Unprotect Password:=PWORD
.Name = .Name & "##"
.Columns.Hidden = False
Else
Set TopCell = .Rows(3).Find(What:="top",
LookIn:=xlValues)
If Not TopCell Is Nothing Then ' if it found
"top"
Set TopCol = .Columns(TopCell.Column)
Set Cols2Hide = .Range(TopCol, .Columns("AC"))
Cols2Hide.Hidden = True
.Protect Password:=PWORD
If .Name Like "*[##]" Then _
.Name = Left(.Name, Len(.Name) - 2)
End If
End With<-----[end with without with error]
Next wkSht
End Sub
But when I run it, I get an error of "End with without if", even
though
there's very clearly a "with wksht" statement at the top. If I
remark
out the End with, I get a "Next without For" error, even though
there's
a "For" statement. So any ideas on why VBA can't see my with or
For
each statements?
Thanks in advance.
Reply With Quote
Don Guillett[_4_]
View Public Profile
Find all posts by Don Guillett[_4_]