+ Reply to Thread
Results 1 to 7 of 7

Not Nothing

  1. #1
    ArthurJ
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: Not Nothing

    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




  3. #3
    Dave Peterson
    Guest

    Re: 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. #4
    ArthurJ
    Guest

    RE: 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. #5
    ArthurJ
    Guest

    RE: 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


  6. #6
    Dave Peterson
    Guest

    Re: 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

  7. #7
    ArthurJ
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1