Autofilter not working in Functions

144725

New Member
Joined
Feb 4, 2009
Messages
5
My workbook has two sheets. Status and worklog sheets. I am trying to get the count of completed work of various phases in the status sheet which reads the data from worklog. Each phase is tracked in a column in worklog sheet. My Worklog look like this,
Col A: Workstream (Values 0-8)
Col B: Iteration (Values 0 -10)
Col H: Analysis (Values Complete, WIP, Yet To Start)
Col I: Clarification (Values Complete, WIP, Yet To Start)
Col J: Design (Values Complete, WIP, Yet To Start) etc.,

In Status sheet, I need the count of Iterations for which the above said phases are completed. So i wrote a function

Function Status(byVal Workstream as Integer, byVal Iteration as Integer, byVal phase as String) Ex: Status(1,5,"Design")

The function should autofilter the worklog with workstream, iteration and phase and return the no. of rows. The column to autofilter for phase is determined by a switch method.
But the ultimate result is, my function doesn't autofilter :(

Interestingly, when I replaced the function with a Sub and passed the count in a Msgbox, it worked. So the problem I have is, the same code for autofilter which worked for Sub doesn't work for function. Any thoughts:confused:
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi, and welome to the Board!

Functions in Excel don't manipulate worksheets; they only return values to the selected cell(s). That is why the Sub will filter but the Function will not.

Denis
 
Upvote 0
Thanks. Can I have a Sub that can autofilter the worklog sheet and have the funtion call the Sub?
 
Upvote 0
Not as far as I know but I am open to correction on that.

If you want to count the number of projects with a set status (using multiple criteria) take a look at the SUMPRODUCT function. There are heaps of examples on the Board.

Denis
 
Upvote 0
AutoFilter changes the environment of the worksheet.
If your function uses AutoFilter to get its result, may work when called by a VB routine, but will fail when called from a worksheet.

If you post your code and an explaination of what it does, a method of getting your result without AutoFilter might be found, that could be called from a spreadsheet.
 
Upvote 0
SUMPRODUCT function served the purpose. It works quicker than my VBA code.

I used the formula =SUMPRODUCT((WorkStream=$B3)*(Iteration=$C3)*(Analysis = "Completed"))

Thanks Denis
 
Upvote 0

Forum statistics

Threads
1,214,859
Messages
6,121,963
Members
449,059
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top