Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

VBA function returns #NAME?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mogens - 20 Mar 2006 16:15 GMT
I have tried to add the below VBA-code from
http://www.ozgrid.com/VBA/autofilter-criteria.htm in a new module, but
it continues to return #NAME? when I try to use the function:

Function AutoFilter_Criteria(Header As Range) As String
Dim strCri1 As String, strCri2 As String

    Application.Volatile

    With Header.Parent.AutoFilter
        With .Filters(Header.Column - .Range.Column + 1)

            If Not .On Then Exit Function

                strCri1 = .Criteria1
            If .Operator = xlAnd Then
                strCri2 = " AND " & .Criteria2
            ElseIf .Operator = xlOr Then
                strCri2 = " OR " & .Criteria2
            End If

        End With
    End With

    AutoFilter_Criteria = UCase(Header) & ": " & strCri1 & strCri2
End Function

Does this indicate an error in the VBA syntax or perhaps that the module
is not made available?

Mogens
Chip Pearson - 20 Mar 2006 16:18 GMT
Where are you putting the code? It should be in a regular code
module, NOT the ThisWorkbook code module or a sheet module.

Signature

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

>I have tried to add the below VBA-code from
>http://www.ozgrid.com/VBA/autofilter-criteria.htm in a new
[quoted text clipped - 29 lines]
>
> Mogens
Niek Otten - 20 Mar 2006 16:29 GMT
How do you call the function (what is your formula)?
Did you try inserting it via the Function wizard?

Signature

Kind regards,

Niek Otten

> Where are you putting the code? It should be in a regular code module, NOT the ThisWorkbook code module or a sheet module.
>
[quoted text clipped - 27 lines]
>>
>> Mogens
mogens - 20 Mar 2006 16:39 GMT
> Where are you putting the code? It should be in a regular code
> module, NOT the ThisWorkbook code module or a sheet module.

Thanks Chip - that explained the error.

I am trying to find a way to see how to qualify for instance how to
select only records with "blanks". This formula didn't give much of an
explanation though.

A shame that you are not able to switch between different criteria for
an autofilter as the advanced filter is a mystery to me (doesn's seem to
update automatically and I can't find somewhere with an easy overview of
criteria definitions) :-(
Tom Ogilvy - 20 Mar 2006 18:00 GMT
field:=1, Criteria1:="="

for blanks

field:=1, Criteria:="<>"

for non-blanks.

Signature

Regards,
Tom Ogilvy

> > Where are you putting the code? It should be in a regular code
> > module, NOT the ThisWorkbook code module or a sheet module.
[quoted text clipped - 9 lines]
> update automatically and I can't find somewhere with an easy overview of
> criteria definitions) :-(
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.