![]() |
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/ |
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/ |
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/ |
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/ |
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/ |
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/ |
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/ |
All times are GMT +1. The time now is 12:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com