Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thanks Robin, that did the trick. Phil "Robin Hammond" wrote: 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Function checkdevFlag() As Boolean If Lower([cdevFlag])= "y" Then checkdevFlag = True Else checkdevFlag = False End If End Function PS. You can read the value from any named range in VBA using syntax [RangeName]. I´m not sure though, what you get when you refer to range which contains several cells. -- Arvi Laanemets ( My real mail address: arvi.laanemets<attarkon.ee ) "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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry! Of course there must be:
..... If LCase([cdevFlag])= "y" Then -- Arvi Laanemets ( My real mail address: arvi.laanemets<attarkon.ee ) "Arvi Laanemets" wrote in message ... Hi Function checkdevFlag() As Boolean If Lower([cdevFlag])= "y" Then checkdevFlag = True Else checkdevFlag = False End If End Function PS. You can read the value from any named range in VBA using syntax [RangeName]. I´m not sure though, what you get when you refer to range which contains several cells. -- Arvi Laanemets ( My real mail address: arvi.laanemets<attarkon.ee ) "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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, I'll try the ([cdevFlag])= format;; much easier to read and type.
Phil "Arvi Laanemets" wrote: Hi Function checkdevFlag() As Boolean If Lower([cdevFlag])= "y" Then checkdevFlag = True Else checkdevFlag = False End If End Function PS. You can read the value from any named range in VBA using syntax [RangeName]. I´m not sure though, what you get when you refer to range which contains several cells. -- Arvi Laanemets ( My real mail address: arvi.laanemets<attarkon.ee ) "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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Wrong! see help on Evaluate for the specifics of using those brackets.. here's a hint [cdevflag] returns "devflag" and is NOT equal to [devflag] [devflag] would evaluate as the value of the named range you're interested in. btw: [[cdevflag]] doesnt work. Admittedly it looks clean and good BUT the evaluate method is slower than using the Range() method Range(cdevflag) is the syntax of choice. -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam pwrichcreek wrote : Thanks, I'll try the ([cdevFlag])= format;; much easier to read and type. Phil "Arvi Laanemets" wrote: Hi Function checkdevFlag() As Boolean If Lower([cdevFlag])= "y" Then checkdevFlag = True Else checkdevFlag = False End If End Function PS. You can read the value from any named range in VBA using syntax [RangeName]. I´m not sure though, what you get when you refer to range which contains several cells. -- Arvi Laanemets ( My real mail address: arvi.laanemets<attarkon.ee ) |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() problem is case sensitivity, "Y" < "y" i also shortened your code to the essentials :) Try: Const cdevFlag As String = "devFlag" Function checkDevFlag() as Boolean on error goto errH checkDevFlag = (UCASE$(Range(cdevFlag)) = "Y") endH: exit function errH: debug.print "range ";cdevflag;" not found in activeworkbook" End Function -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam pwrichcreek wrote : 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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks keepIT. I got caught up in the notion that, in an EXCEL formula,
=if(devFlag="y") is the same as =if(defFlag="Y"). I should have realized that VBA would be more precise. It's also very instructive to know that Dim rdevFlag As Range Set rdevFlag = Names.Item(cdevFlag).RefersToRange If (rdevFlag.Value = "y") Then checkdevFlag = True Else checkdevFlag = False End If can be reduced to checkDevFlag = (UCASE$(Range(cdevFlag)) = "Y") As you no doubt have observed, I'm not a VB programmer, but I have done a fair amount of perl code. It's refreshing to see that VB does not have to be as verbose as I may have expected. Thanks, Phil "keepITcool" wrote: problem is case sensitivity, "Y" < "y" i also shortened your code to the essentials :) Try: Const cdevFlag As String = "devFlag" Function checkDevFlag() as Boolean on error goto errH checkDevFlag = (UCASE$(Range(cdevFlag)) = "Y") endH: exit function errH: debug.print "range ";cdevflag;" not found in activeworkbook" End Function -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam pwrichcreek wrote : 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cell references in excel vba code | Excel Discussion (Misc queries) | |||
convert relative cell references to absolute cell references via amacro? | Excel Discussion (Misc queries) | |||
How to rename references from range names to cell references | Excel Discussion (Misc queries) | |||
Relative Cell References within VBA code | Excel Discussion (Misc queries) | |||
syntax question - cell references in VB code | New Users to Excel |