Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need help with Formula. Need it to return Null, not Blank | Excel Discussion (Misc queries) | |||
Delete Null/Blank Rows | Excel Discussion (Misc queries) | |||
If null, make cell blank | Excel Worksheet Functions | |||
COUNTIF says Null = Blank but Blank < Null | Excel Worksheet Functions | |||
How can I refer to a blank cell when using conditional formating? | Excel Discussion (Misc queries) |