Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA function returns #NAME?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA function returns #NAME?

Where are you putting the code? It should be in a regular code
module, NOT the ThisWorkbook code module or a sheet module.


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


"mogens" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default VBA function returns #NAME?

How do you call the function (what is your formula)?
Did you try inserting it via the Function wizard?

--
Kind regards,

Niek Otten

"Chip Pearson" wrote in message ...
Where are you putting the code? It should be in a regular code module, NOT the ThisWorkbook code module or a sheet module.


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


"mogens" wrote in message ...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA function returns #NAME?

Chip Pearson wrote:
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) :-(

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VBA function returns #NAME?

field:=1, Criteria1:="="

for blanks

field:=1, Criteria:="<"

for non-blanks.

--
Regards,
Tom Ogilvy




"mogens" wrote:

Chip Pearson wrote:
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) :-(


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
IF function returns function statement rather than result ckrogers Excel Worksheet Functions 3 April 16th 09 09:21 PM
If function returns #REF!, want it to return 0 rancher fred Excel Worksheet Functions 2 January 6th 07 04:18 AM
INT Function Returns 1 bhavesh Excel Worksheet Functions 3 December 29th 06 02:48 PM
Date function returns #NUM! [email protected] Excel Worksheet Functions 5 May 10th 06 06:15 PM
Function returns a zero value Dick Kusleika Excel Programming 0 July 29th 03 05:01 PM


All times are GMT +1. The time now is 09:03 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"