+ Reply to Thread
Results 1 to 6 of 6

How to evaluate a blank field

  1. #1
    Susan
    Guest

    How to evaluate a blank field

    I need to increment a number if the name field is blank but not if there is a
    name already entered. The name field is defined as a 'general' field. I
    thought I was on to something with a previous post regarding the IsNull
    function (Thanks SusanV). However, it appears I'm getting a true result on
    the IsNull test regardless of whether there is data in the field or not.

    I've written the code as (D8 is the name field):

    If IsNull(D8) Then
    Code to increment the number and save goes here

    But even when the name is blank (tested with a MsgBox) it's still not
    performing the code.

    Any help is greatly appreciated.

  2. #2
    Dave Peterson
    Guest

    Re: How to evaluate a blank field

    Maybe...

    if isempty(worksheets("Sheet99").range("D8")) then
    ...



    Susan wrote:
    >
    > I need to increment a number if the name field is blank but not if there is a
    > name already entered. The name field is defined as a 'general' field. I
    > thought I was on to something with a previous post regarding the IsNull
    > function (Thanks SusanV). However, it appears I'm getting a true result on
    > the IsNull test regardless of whether there is data in the field or not.
    >
    > I've written the code as (D8 is the name field):
    >
    > If IsNull(D8) Then
    > Code to increment the number and save goes here
    >
    > But even when the name is blank (tested with a MsgBox) it's still not
    > performing the code.
    >
    > Any help is greatly appreciated.


    --

    Dave Peterson

  3. #3
    Susan
    Guest

    Re: How to evaluate a blank field

    Thanks Dave but that doesn't work either. For some reason, even when the
    field is empty I'm getting a false return on the isempty function....

    "Dave Peterson" wrote:

    > Maybe...
    >
    > if isempty(worksheets("Sheet99").range("D8")) then
    > ...
    >
    >
    >
    > Susan wrote:
    > >
    > > I need to increment a number if the name field is blank but not if there is a
    > > name already entered. The name field is defined as a 'general' field. I
    > > thought I was on to something with a previous post regarding the IsNull
    > > function (Thanks SusanV). However, it appears I'm getting a true result on
    > > the IsNull test regardless of whether there is data in the field or not.
    > >
    > > I've written the code as (D8 is the name field):
    > >
    > > If IsNull(D8) Then
    > > Code to increment the number and save goes here
    > >
    > > But even when the name is blank (tested with a MsgBox) it's still not
    > > performing the code.
    > >
    > > Any help is greatly appreciated.

    >
    > --
    >
    > Dave Peterson
    >


  4. #4
    Dave Peterson
    Guest

    Re: How to evaluate a blank field

    Then the cell isn't really empty.

    It could look empty for a few reasons:
    1. The user hit the space bar instead of the delete key to "clear" the contents
    of the cell.

    2. You could have had a formula that evaluated to "" (=if(a1="","",a1) and then
    converted to values.

    Each of these leaves the cell non-empty.

    maybe just looking at the .value would be sufficient:

    if trim(worksheets("sheet99").range("d8").value) = "" then
    .....



    Susan wrote:
    >
    > Thanks Dave but that doesn't work either. For some reason, even when the
    > field is empty I'm getting a false return on the isempty function....
    >
    > "Dave Peterson" wrote:
    >
    > > Maybe...
    > >
    > > if isempty(worksheets("Sheet99").range("D8")) then
    > > ...
    > >
    > >
    > >
    > > Susan wrote:
    > > >
    > > > I need to increment a number if the name field is blank but not if there is a
    > > > name already entered. The name field is defined as a 'general' field. I
    > > > thought I was on to something with a previous post regarding the IsNull
    > > > function (Thanks SusanV). However, it appears I'm getting a true result on
    > > > the IsNull test regardless of whether there is data in the field or not.
    > > >
    > > > I've written the code as (D8 is the name field):
    > > >
    > > > If IsNull(D8) Then
    > > > Code to increment the number and save goes here
    > > >
    > > > But even when the name is blank (tested with a MsgBox) it's still not
    > > > performing the code.
    > > >
    > > > Any help is greatly appreciated.

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  5. #5
    Chip Pearson
    Guest

    Re: How to evaluate a blank field

    You can test for an empty string or use the IsEmpty function.


    Debug.Print Range("A1").Value = ""
    Debug.Print IsEmpty(Range("A1"))



    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com



    "Susan" <[email protected]> wrote in message
    news:[email protected]...
    >I need to increment a number if the name field is blank but not
    >if there is a
    > name already entered. The name field is defined as a 'general'
    > field. I
    > thought I was on to something with a previous post regarding
    > the IsNull
    > function (Thanks SusanV). However, it appears I'm getting a
    > true result on
    > the IsNull test regardless of whether there is data in the
    > field or not.
    >
    > I've written the code as (D8 is the name field):
    >
    > If IsNull(D8) Then
    > Code to increment the number and save goes here
    >
    > But even when the name is blank (tested with a MsgBox) it's
    > still not
    > performing the code.
    >
    > Any help is greatly appreciated.




  6. #6
    Susan
    Guest

    Re: How to evaluate a blank field

    Thank you Dave and Chip. The Trim function worked great. Thanks again -
    Happy New Year

    "Chip Pearson" wrote:

    > You can test for an empty string or use the IsEmpty function.
    >
    >
    > Debug.Print Range("A1").Value = ""
    > Debug.Print IsEmpty(Range("A1"))
    >
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    >
    > "Susan" <[email protected]> wrote in message
    > news:[email protected]...
    > >I need to increment a number if the name field is blank but not
    > >if there is a
    > > name already entered. The name field is defined as a 'general'
    > > field. I
    > > thought I was on to something with a previous post regarding
    > > the IsNull
    > > function (Thanks SusanV). However, it appears I'm getting a
    > > true result on
    > > the IsNull test regardless of whether there is data in the
    > > field or not.
    > >
    > > I've written the code as (D8 is the name field):
    > >
    > > If IsNull(D8) Then
    > > Code to increment the number and save goes here
    > >
    > > But even when the name is blank (tested with a MsgBox) it's
    > > still not
    > > performing the code.
    > >
    > > Any help is greatly appreciated.

    >
    >
    >


+ 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