Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to refer to a blank/null value?

I have the following If Else statement:

If CDbl(myString) < "" Then
cells(n,9).Value = CDbl(myString)
End If


However, it doesn't work. MyString is declared as a String and it is
copying a field from another application. How can I check that
myString is empty/null?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default How to refer to a blank/null value?

I'd do it this way:

If myString<"" Then
cells(n,9).Value = CDbl(myString)
End If


"desmondleow" wrote in message
...
I have the following If Else statement:

If CDbl(myString) < "" Then
cells(n,9).Value = CDbl(myString)
End If


However, it doesn't work. MyString is declared as a String and it is
copying a field from another application. How can I check that
myString is empty/null?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to refer to a blank/null value?

Desmond,

Why cast it to a double and then test as a string?

Various tests you can try

If IsEmty(myString) Then

If myString = "" Then

If Len(myString) = 0 Then

In your example, this should wotk

If myString < "" Then
Cells(n, 9).Value = CDbl(myString)
End If

but you might want to test myString for a numeric value before casting to a
double.




Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"desmondleow" wrote in message
...
I have the following If Else statement:

If CDbl(myString) < "" Then
cells(n,9).Value = CDbl(myString)
End If


However, it doesn't work. MyString is declared as a String and it is
copying a field from another application. How can I check that
myString is empty/null?


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to refer to a blank/null value?

Hi there

The problem is almost certainly due to the CDbl(myString) - this forces
Excel to convert myString to "a data type that holds double-precision
floating-point numbers" - try removing both references to CDbl from the code
and see what happens...

However, I'm surprised that it allows the code to run at all - testing
CDbl(myString) with myString set to "Fred" results in a type mis-match
error - are you convinced that myString really is a string?

Regards

David

***** MY TEST CODE *****
***** set mystring to "" or "fred" and you should see the results that
you're expecting....

Sub macro1()

mystring = ""

If ((mystring) < "") Then MsgBox ("Non-empty string") Else MsgBox ("empty
string")

End Sub



"desmondleow" wrote in message
...
I have the following If Else statement:

If CDbl(myString) < "" Then
cells(n,9).Value = CDbl(myString)
End If


However, it doesn't work. MyString is declared as a String and it is
copying a field from another application. How can I check that
myString is empty/null?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to refer to a blank/null value?

Is there anyway to test myString for a numeric value before I cast it to
a double?


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to refer to a blank/null value?

IsNumber (myString) should do the trick (IsText exists if you want to check
the other way)

Regards

David



"desmondleow" wrote in message
...
Is there anyway to test myString for a numeric value before I cast it to
a double?


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default How to refer to a blank/null value?

try IsNumeric() function

"desmondleow" wrote in message
...
Is there anyway to test myString for a numeric value before I cast it to
a double?


---
Message posted from http://www.ExcelForum.com/



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Formula. Need it to return Null, not Blank Aled Davies Excel Discussion (Misc queries) 0 January 27th 11 04:20 PM
Delete Null/Blank Rows Theresa Excel Discussion (Misc queries) 8 December 18th 07 05:17 AM
If null, make cell blank Nicole L. Excel Worksheet Functions 1 September 30th 07 08:25 AM
COUNTIF says Null = Blank but Blank < Null Epinn Excel Worksheet Functions 4 October 25th 06 08:03 PM
How can I refer to a blank cell when using conditional formating? Kman Excel Discussion (Misc queries) 2 June 23rd 06 05:22 AM


All times are GMT +1. The time now is 10:54 PM.

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

About Us

"It's about Microsoft Excel"