Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code that references the name of a cell

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   Report Post  
Posted to microsoft.public.excel.programming
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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code that references the name of a cell


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Code that references the name of a cell

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Code that references the name of a cell

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code that references the name of a cell

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Code that references the name of a cell


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Code that references the name of a cell



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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code that references the name of a cell

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell references in excel vba code Isis[_2_] Excel Discussion (Misc queries) 4 April 26th 10 01:10 PM
convert relative cell references to absolute cell references via amacro? Dave F[_2_] Excel Discussion (Misc queries) 1 May 15th 08 04:43 PM
How to rename references from range names to cell references Abbas Excel Discussion (Misc queries) 1 May 24th 06 06:18 PM
Relative Cell References within VBA code Jandy Excel Discussion (Misc queries) 2 April 21st 05 02:17 AM
syntax question - cell references in VB code needyourhelp New Users to Excel 1 March 2nd 05 08:52 PM


All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"