ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to evaluate a blank field (https://www.excelbanter.com/excel-programming/349324-how-evaluate-blank-field.html)

Susan

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.

Dave Peterson

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

Susan

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


Dave Peterson

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

Chip Pearson

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




Susan

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






All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com