This works:
If ActiveChart Is Nothing Then
**code**
End If
But what I need is the reverse of this, as in ...
If ActiveChart Is 'Not' Nothing, or
If ActiveChart is 'Something'
Of course neither of these work.
How do I do this?
Art
This works:
If ActiveChart Is Nothing Then
**code**
End If
But what I need is the reverse of this, as in ...
If ActiveChart Is 'Not' Nothing, or
If ActiveChart is 'Something'
Of course neither of these work.
How do I do this?
Art
If Not ActiveChart Is Nothing Then
--
HTH
Bob Phillips
(replace xxxx in the email address with gmail if mailing direct)
"ArthurJ" <[email protected]> wrote in message
news:[email protected]...
> This works:
>
> If ActiveChart Is Nothing Then
> **code**
> End If
>
> But what I need is the reverse of this, as in ...
>
> If ActiveChart Is 'Not' Nothing, or
> If ActiveChart is 'Something'
>
> Of course neither of these work.
>
> How do I do this?
>
> Art
if not activechart is nothing then
or
if not (activechart is nothing) then
or I'd use:
if activechart is nothing then
'do it's nothing stuff
else
'do if it's "something" stuff
end if
I find the last one much easier to wrap my brain around (I don't like double
negatives <bg>).
Well, except in =sumproduct()'s. (An excel joke!)
ArthurJ wrote:
>
> This works:
>
> If ActiveChart Is Nothing Then
> **code**
> End If
>
> But what I need is the reverse of this, as in ...
>
> If ActiveChart Is 'Not' Nothing, or
> If ActiveChart is 'Something'
>
> Of course neither of these work.
>
> How do I do this?
>
> Art
--
Dave Peterson
Thank you Bob and Dave. Just what I needed.
Dave, the reason I didn't use the following structure ....
if activechart is nothing then
'do it's nothing stuff
else
'do if it's "something" stuff
end if
..... is that the 'nothing stuff' is many lines of code
while the 'something stuff' is zero lines. That makes
the If-Then-Else statement really hard to read!
Art
Thank you Bob and Dave. Just what I needed.
Dave, the reason I didn't use the following structure ....
if activechart is nothing then
'do it's nothing stuff
else
'do if it's "something" stuff
end if
..... is that the 'nothing stuff' is many lines of code
while the 'something stuff' is zero lines. That makes
the If-Then-Else statement really hard to read!
Art
I don't think this looks bad:
if activechart is nothing then
'your lots of code here
end if
===
and I use this all the time:
if something = true then
'do nothing
else
a bunch of code here
end if
I actually put the characters "'Do nothing" in the code--for readability sake
only.
Kind of like "NEXT SENTENCE" in COBOL.
ArthurJ wrote:
>
> Thank you Bob and Dave. Just what I needed.
>
> Dave, the reason I didn't use the following structure ....
>
> if activechart is nothing then
> 'do it's nothing stuff
> else
> 'do if it's "something" stuff
> end if
>
> .... is that the 'nothing stuff' is many lines of code
> while the 'something stuff' is zero lines. That makes
> the If-Then-Else statement really hard to read!
>
> Art
--
Dave Peterson
'I thought my question was resolved, and it is, well, sort of ....
'Can anyone explain the peculiar behavior of the second macro?
Sub testDeactivate1()
'Crashes if there is no active chart.
Worksheets(2).Activate
ActiveChart.Deselect
End Sub
Sub testDeActivate2()
'This sub does not crash and the end result is that there
'is no active chart.
'But the odd thing is that if there is
'NOTHING selected (including cells) then the macro branches through
'the Then part of the If statement (even though there is no
'active chart). Yet it does not crash!
'Contrast this behavior with the other sub, which crashes if there is
'no active chart.
'If there is a cell range selected, the macro branches through
'the Else portion of the routine.
Worksheets(2).Activate
If Not (ActiveChart Is Nothing) Then
MsgBox ("There IS an active chart")
ActiveChart.Deselect
MsgBox ("Not any more!")
Else
MsgBox ("There is NOT an active chart.")
End If
End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks