#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Not Nothing

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default Not Nothing

If Not ActiveChart Is Nothing Then


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"ArthurJ" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Not Nothing

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Not Nothing

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Not Nothing

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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Not Nothing

'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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"