View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default TypeName function

Along similar lines, to avoid case sensitivity with string comparisons could
head the module -

Option Compare Text

In general though best not to use that without specific reason.

Regards,
Peter T

"Rick Rothstein" wrote in message
...
As others have pointed out, you needed to use "String", not "string".
Whenever you do a logical test against a String constant (text within
quote marks), you must always be wary of case sensitivity. Some functions
(like InStr or Replace) have optional arguments whereby you can make the
comparison case insensitive; but others (like TypeName) do not.

--
Rick (MVP - Excel)


"Mike H" wrote in message
...
Hi,

Try this. Note a few less parenthesis

Sub Test()
'The active cell contains the string "ABC"
MsgBox ActiveCell.Value 'Displays 'ABC'
MsgBox TypeName(ActiveCell.Value) 'Displays 'String'
MsgBox TypeName(ActiveCell.Value) = TypeName("String") 'Displays
'FALSE'
End Sub

Mike

"ArthurJ" wrote:

Why does the last message box return FALSE when testing a cell for a
string?
I have the same problem checking for numeric values such as Double.

Sub Test()
'The active cell contains the string "ABC"
MsgBox (ActiveCell.Value) 'Displays 'ABC'
MsgBox (TypeName(ActiveCell.Value)) 'Displays 'String'
MsgBox (TypeName(ActiveCell.Value) = "string") 'Displays 'FALSE'
End Sub