How can I pass a named range from an excel vba function into an excel database function like dcount?

:  How can I pass a named range from an excel vba function into an excel database function like dcount?

The below call in an excel cell works fine.

=DCOUNTA([DataWorkbook]Data!_FilterDatabase,"Field1",NAMED_RANGE)

I would like NAMED_RANGE to come from my own VBA function.  Something like:

Function criteriaRangeLookup(lookupField as integer) As Range

if lookukpField = 1 then
   criteriaRangeLookup =Range("'NAMED_RANGE")
end if
end function

I would then like DCOUNTA to work as follows:

=DCOUNTA([DataWorkbook]Data!_FilterDatabase,"Field1",criteriaRangeLookup(1))

However this does not work.  How can I get something like this to work?

Function criteriaRangeLookup(lookupField as integer) As Range
    if lookukpField = 1 then 
        criteriaRangeLookup =Range("'NAMED_RANGE")
    end if
end function

Open in new window

jnash67Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
It does work but your function is incorrect:

Function criteriaRangeLookup(lookupField as integer) As Range
    if lookupField = 1 then
        set criteriaRangeLookup =Range("'NAMED_RANGE")
    end if
end function

Regards,
Rory
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jnash67Author Commented:
Thanks.  It's always the simple things that screw you up.
0
Rory ArchibaldCommented:
Ain't that the truth. Thanks for the grade.
Rory
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.