Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Syntax problem fassing named range into function

Hi,
I have a function that works when I pass in a string for a range name

I need to extend it to use an array and then loop it. Can't figure it out.


Any help appereciated


Works
If NameExists("exampleRangeName", Workbooks(ActiveWorkbook.Name)) Then

Doesn't work
MyRange(1,1)="exampleRangeName"

If NameExists((myRange(1 1)), Workbooks(ActiveWorkbook.Name)) Then


Function NameExists(WhatName As String, Optional WB As Workbook) As Boolean
Dim N As Long
On Error Resume Next
'Y = WB.Name
N = Len(IIf(WB Is Nothing, ThisWorkbook, WB).Names(WhatName).Name)
NameExists = (Err.Number = 0)
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Syntax problem fassing named range into function

You need to cast the MyRange(1,1) value to a String type of variable,
since that is how the WhatName parameter of NameExists is declared.

E.g.,

B = NameExists(CStr(MyRange(1, 1)), ActiveWorkbook)

The CStr function converts whatever is in MyRange(1,1) to an explicit
String type, which is how the WhatName parameter to NameExists is
declared.


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Thu, 11 Dec 2008 14:35:01 -0800, Pete Mac <Pete
wrote:

Hi,
I have a function that works when I pass in a string for a range name

I need to extend it to use an array and then loop it. Can't figure it out.


Any help appereciated


Works
If NameExists("exampleRangeName", Workbooks(ActiveWorkbook.Name)) Then

Doesn't work
MyRange(1,1)="exampleRangeName"

If NameExists((myRange(1 1)), Workbooks(ActiveWorkbook.Name)) Then


Function NameExists(WhatName As String, Optional WB As Workbook) As Boolean
Dim N As Long
On Error Resume Next
'Y = WB.Name
N = Len(IIf(WB Is Nothing, ThisWorkbook, WB).Names(WhatName).Name)
NameExists = (Err.Number = 0)
End Function

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
Syntax for getting value of named workbook range Barb Reinhardt Excel Programming 1 August 10th 07 07:46 PM
Named Range Problem David Excel Programming 2 May 6th 07 03:06 PM
Syntax problem defining range for pivot table Richard Excel Programming 0 March 14th 06 06:52 PM
named range problem Rbp9ad[_2_] Excel Programming 4 December 1st 05 10:21 PM
syntax to go to a named range Ben Excel Programming 3 November 30th 05 01:30 PM


All times are GMT +1. The time now is 12:41 AM.

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

About Us

"It's about Microsoft Excel"