Re: End if w/o if?
- From: "Charlie" <Charlie@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Apr 2005 08:36:03 -0700
I agree with Don. Single-line If's save space and there's no lack of clarity
to me. I only indent the If -- Then -- Else -- End If constructs. Your
indenting problems MAY be due to ElseIf's. Those I avoid like the plague.
They are difficult to balance and indent (not one End If per If) But these
are just personal style preferences.
"Bob Phillips" wrote:
> I avoid them like the plague Don, spent too much wasted time trying to line
> up Ifs ... End Ifs. I think the lack of clarity and potential maintenance
> overhead dwarfs the initial effort.
>
> The only time I use anything like that is with Iif.
>
> Regards
>
> Bob
>
> "Don Guillett" <donaldb@xxxxxxx> wrote in message
> news:OxhpbJnSFHA.1236@xxxxxxxxxxxxxxxxxxxxxxx
> > I use single line ifs much of the time
> >
> > --
> > Don Guillett
> > SalesAid Software
> > donaldb@xxxxxxx
> > "Toppers" <Toppers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > news:A7B69EAA-3F6C-4C82-B0C8-F63590B3FC38@xxxxxxxxxxxxxxxx
> > > 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" <Toppers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > > > news:576C31D0-B553-4F68-BC1A-B50EA74828F7@xxxxxxxxxxxxxxxx
> > > > > 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" <Toppers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > > > > > news:26927AED-559E-4246-84E6-1D32263FAB3B@xxxxxxxxxxxxxxxx
> > > > > > > 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 Work***
> > > > > > > >
> > > > > > > > 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.
> > > > > > > >
> > > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> >
> >
>
>
>
.
- Follow-Ups:
- Re: End if w/o if?
- From: Bob Phillips
- Re: End if w/o if?
- References:
- End if w/o if?
- From: davegb
- RE: End if w/o if?
- From: Toppers
- Re: End if w/o if?
- From: Bob Phillips
- Re: End if w/o if?
- From: Toppers
- Re: End if w/o if?
- From: Bob Phillips
- Re: End if w/o if?
- From: Toppers
- Re: End if w/o if?
- From: Don Guillett
- Re: End if w/o if?
- From: Bob Phillips
- End if w/o if?
- Prev by Date: Re: End if w/o if?
- Next by Date: How to import a matrix of size 2057x2057
- Previous by thread: Re: End if w/o if?
- Next by thread: Re: End if w/o if?
- Index(es):