+ Reply to Thread
Results 1 to 9 of 9

Need help with an if statement

Hybrid View

  1. #1
    Zone
    Guest

    Re: Need help with an if statement

    Bob,
    This topic interests me, so I'll barge in. This does not seem to
    work:

    Sub RangeStatus2()
    Dim z As Range
    Set z = [a1:b5]
    If IsEmpty(z.Value) Then
    MsgBox "empty"
    Else
    MsgBox "not empty"
    End If
    End Sub

    What did I do wrong?
    James


    Bob Phillips wrote:
    > If rng.Value = "" Then
    >
    > or
    >
    > If IsEmpty(rng.Value) Then
    >
    > or
    >
    > If Len(rng.value) = 0 Then
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "SuitedAces" <SuitedAces.2a40b5_1151493324.046@excelforum-nospam.com> wrote
    > in message news:SuitedAces.2a40b5_1151493324.046@excelforum-nospam.com...
    > >
    > > I have Dim a variable as a range.
    > >
    > > I am trying to write an IF statement based on that range being empty,
    > > and having no success.
    > >
    > > Any help is appreciated.
    > >
    > >
    > > --
    > > SuitedAces
    > > ------------------------------------------------------------------------
    > > SuitedAces's Profile:

    > http://www.excelforum.com/member.php...o&userid=35840
    > > View this thread: http://www.excelforum.com/showthread...hreadid=556412
    > >



  2. #2
    Bob Phillips
    Guest

    Re: Need help with an if statement

    Zone,

    IsEmpty is used to test if a variable is has been initialized. This does
    work with a single cell value as this is a simple variant, but not a range
    of cells, as this is a 2 dimensional array of values. Even though all of the
    elements of the array are empty, the array is not.

    You need to test a range differently, either loop through them, or use a
    worksheet function

    Sub RangeStatus2()
    Dim z As Range
    Set z = Range("A1:B5")
    If Application.CountIf(z, "<>") = 0 Then
    MsgBox "empty"
    Else
    MsgBox "not empty"
    End If
    End Sub


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Zone" <jkend69315@aol.com> wrote in message
    news:1151497234.295372.106810@d56g2000cwd.googlegroups.com...
    > Bob,
    > This topic interests me, so I'll barge in. This does not seem to
    > work:
    >
    > Sub RangeStatus2()
    > Dim z As Range
    > Set z = [a1:b5]
    > If IsEmpty(z.Value) Then
    > MsgBox "empty"
    > Else
    > MsgBox "not empty"
    > End If
    > End Sub
    >
    > What did I do wrong?
    > James
    >
    >
    > Bob Phillips wrote:
    > > If rng.Value = "" Then
    > >
    > > or
    > >
    > > If IsEmpty(rng.Value) Then
    > >
    > > or
    > >
    > > If Len(rng.value) = 0 Then
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (replace somewhere in email address with gmail if mailing direct)
    > >
    > > "SuitedAces" <SuitedAces.2a40b5_1151493324.046@excelforum-nospam.com>

    wrote
    > > in message

    news:SuitedAces.2a40b5_1151493324.046@excelforum-nospam.com...
    > > >
    > > > I have Dim a variable as a range.
    > > >
    > > > I am trying to write an IF statement based on that range being empty,
    > > > and having no success.
    > > >
    > > > Any help is appreciated.
    > > >
    > > >
    > > > --
    > > > SuitedAces

    > >

    > ------------------------------------------------------------------------
    > > > SuitedAces's Profile:

    > > http://www.excelforum.com/member.php...o&userid=35840
    > > > View this thread:

    http://www.excelforum.com/showthread...hreadid=556412
    > > >

    >




+ 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