Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default function called from worksheet and bad result!

Hi,
in a worksheet "test" with autofilter mode, I'm using the formula:

=nb_row_aera(1)

which refers to my VBA function :

Function nb_row_area(n as Long) As Long
nb_row_area
Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n).Rows.Count
End Function

the problem is that the result is always the nb of rows in the initia
range for Autofilter even if filters are activated in the worksheet!
On the contrary, the same code placed into a macro provides goo
results!!!

Sub Pr_nb_row_area()
n = 1
MsgBo
Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n).Rows.Count
End Sub

Why and how should I modify the function

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default function called from worksheet and bad result!

Excel doesn't know when to recalculate your formula because no cells are
used as arguments.
You can add "Application.Volatile" as the first line in your function; then
it will always be recalculated.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"@lan " wrote in message
...
Hi,
in a worksheet "test" with autofilter mode, I'm using the formula:

=nb_row_aera(1)

which refers to my VBA function :

Function nb_row_area(n as Long) As Long
nb_row_area =

Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n)
..Rows.Count
End Function

the problem is that the result is always the nb of rows in the initial
range for Autofilter even if filters are activated in the worksheet!
On the contrary, the same code placed into a macro provides good
results!!!

Sub Pr_nb_row_area()
n = 1
MsgBox

Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n)
..Rows.Count
End Sub

Why and how should I modify the function?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default function called from worksheet and bad result!

Unfortunately no change with (even with F9):

Function nb_row_area(n As Long) As Long
Application.Volatile
nb_row_area
Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n).Rows.Count
End Function

should I activate an option for use of Application.Volatile

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default function called from worksheet and bad result!

Several methods don't work when used as a UDF. I believe specialcells is
one of those.

You may have to loop throught the range in your UDF or better, use the
already builtin Subtotal worksheet function.

=Subtotal(3,A1:A100)-1

Assumes that column A will contain an entry for each record.

--
Regards,
Tom Ogilvy



"@lan " wrote in message
...
Unfortunately no change with (even with F9):

Function nb_row_area(n As Long) As Long
Application.Volatile
nb_row_area =

Worksheets("test").AutoFilter.Range.SpecialCells(x lCellTypeVisible).Areas(n)
..Rows.Count
End Function

should I activate an option for use of Application.Volatile?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default function called from worksheet and bad result!

in fact I would like to build a function to return the number o
different values in column A for example taking current filtering int
account (I think there's no appropriate function with subtotal).

My whole procedure using SpecialCells(xlCellTypeVisible) works well bu
not the same code in the function!

Do you have any other suggestions or tricks to get round the problem

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default function called from worksheet and bad result!

Loop through the cells of the filtered area and check if the row is hidden
or not.

--
Regards,
Tom Ogilvy

"@lan " wrote in message
...
in fact I would like to build a function to return the number of
different values in column A for example taking current filtering into
account (I think there's no appropriate function with subtotal).

My whole procedure using SpecialCells(xlCellTypeVisible) works well but
not the same code in the function!

Do you have any other suggestions or tricks to get round the problem?


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default function called from worksheet and bad result!

effectively method Hidden works in UDF unlike SpecialCells.

Tom and Niek, thank you

--
Message posted from http://www.ExcelForum.com

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
Incorrect result using NPER worksheet function KG Old Wolf Excel Worksheet Functions 7 November 3rd 08 02:49 AM
How do I display the result of a function on seperate worksheet e. Beth Excel Worksheet Functions 3 July 15th 08 05:30 AM
Link a cell from another worksheet as a result in a function? LisaLisaKK Excel Worksheet Functions 1 September 7th 06 06:47 PM
How can I put result of If worksheet function into a different cel Janice Excel Worksheet Functions 1 August 30th 05 08:01 PM
Possible to know who has called a function ? Isabelle Robin Excel Programming 3 March 5th 04 12:33 AM


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