View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default Code that references the name of a cell

Phil,

Try this:

Function checkdevFlag() As Boolean
checkdevFlag = (UCase(Range("devFlag").Text) = "Y")
End Function

Robin Hammond
www.enhanceddatasystems.com

"pwrichcreek" wrote in message
...
I have a cell named "devFlag" in my spreadsheet and I want to examine its
contents in VBA code. The cell contains the value "Y", but this code
returns
FALSE.

Const cdevFlag As String = "devFlag"
Const cchktot As String = "check_totals"
Function checkdevFlag() As Boolean
Dim rdevFlag As Range
Set rdevFlag = Names.Item(cdevFlag).RefersToRange
If (rdevFlag.Value = "y") Then
checkdevFlag = True
Else
checkdevFlag = False
End If
End Function

My intent is to use the function in other VBA code, but for testing I've
tried using the function in an IF as:
=IF(checkdevFlag(),"devFlag is y","not") this returns "not"

and as:
=checkdevFlag() this returns FALSE

Can someone see what I am doing wrong?

TIA,

Phil