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 / Worksheet Functions / September 2007

Tip: Looking for answers? Try searching our database.

Do not allow Narrow Down with AutoFilter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sargum@umich.edu - 10 Sep 2007 14:53 GMT
Hello,

I have an Excel 2003 file with >8 columns that one could filter on.
The AutoFilter function is set to ON.  I have found that the users do
not always remember to click on (All) in the filter drop down menu
before moving to the next column and filtering...they end up with
narrowing down on their filter choices when all they wanted to do was
filter exclusively on the next column criteria.

With this dataset, there will never be a need to narrow down...Hence,
how do I make it so that if one moves to another column to filter, it
automatically sets everything back to (All)?  There are way too many
users to train to select (All) every time they move to a different
column to filter on a different subject so a solution here would be of
great help!

Sargum
Bernie Deitrick - 10 Sep 2007 15:41 GMT
Sargum,

Copy the code below, then right-click the sheet tab and select "View Code". Paste the code into the
window that appears.

HTH,
Bernie
MS Excel MVP

Public myCol As Integer

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If myCol = 0 Then myCol = Target.Cells(1).Column
If myCol <> Target.Cells(1).Column Then
  If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
  myCol = Target.Cells(1).Column
End If

End Sub

> Hello,
>
[quoted text clipped - 13 lines]
>
> Sargum
Roger Govier - 10 Sep 2007 16:37 GMT
Hi Bernie

That works perfectly as long as the user selects the cell with the dropdown,
before selecting the dropdown itself.
Regrettably, if the user goes straight to the filter dropdown button, whilst
a selection is in place, the SelectionChange event doesn't get triggered.
I have been trying to figure out a way around this, and decided that a
modification of Debra's code (that I directed the OP to), would achieve both
the task of colouring the active filtered cell, and preventing 2 filters
being set at the same time.

Selecting a second filter, causes ShowAlldata, and the user has to select
the filter required again.

Private Sub Worksheet_Calculate()
'rem Code created by Debra Dalgleish
'modified by Roger Govier

 Dim af As AutoFilter
 Dim fFilter As Filter
 Dim iFilterCount As Integer

 If ActiveSheet.AutoFilterMode Then
' additional lines of code inserted here

 Set af = ActiveSheet.AutoFilter
   iFilterCount = 0
   For Each fFilter In af.Filters
     If fFilter.On Then iFilterCount = iFilterCount + 1
   Next

 If iFilterCount > 1 Then
 Rows(1).EntireRow.Interior.ColorIndex = xlNone
 ActiveSheet.ShowAllData
 Exit Sub
 End If

'additional lines end here

   Set af = ActiveSheet.AutoFilter
   iFilterCount = 1
   For Each fFilter In af.Filters
     If fFilter.On Then
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = 6
     Else
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = xlNone
     End If
     iFilterCount = iFilterCount + 1
   Next fFilter
 Else
   Rows(1).EntireRow.Interior.ColorIndex = xlNone
 End If
End Sub

Signature

Regards
Roger Govier

> Sargum,
>
[quoted text clipped - 33 lines]
>>
>> Sargum
Roger Govier - 10 Sep 2007 15:58 GMT
Hi

Whilst the following suggestion won't change the selection, it may help
users to recognise that a filter has already been set. Although the small
arrow on the filter button turns blue when selection is on, this is hard to
see.

Debra Dalgleish has several downloadable example sheets on her site, where
the cell containing the heading becomes coloured if a filter is applied.
Users could be told that not more than one heading should be coloured for
their selection to be correct.

http://www.contextures.com/FilterColour.zip

Signature

Regards
Roger Govier

> Hello,
>
[quoted text clipped - 13 lines]
>
> Sargum
sargum@umich.edu - 10 Sep 2007 16:16 GMT
On Sep 10, 10:58 am, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
wrote:
> Hi
>
[quoted text clipped - 37 lines]
>
> - Show quoted text -

Hello,

I appreciate your help but I did as you mentioned...I added the code
but it did not automatically go back to (All) after one moved to the
next column to filter on a different subject.  It is narrowing down
still as it did before.

Sargum
sargum@umich.edu - 10 Sep 2007 16:28 GMT
On Sep 10, 10:58 am, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
wrote:
> Hi
>
[quoted text clipped - 37 lines]
>
> - Show quoted text -

Hi Roger,

I like this suggestion a lot and have added the code...I right-clicked
and chose "View Code" and pasted.  However, similar to Bernie's code,
nothing happened.  Is there something else I am supposed to do after I
paste the code and close VB?  I must be missing something here since
both yours and Bernie's code have not worked for me yet.  I will play
around with it.

Sargum
Bernie Deitrick - 10 Sep 2007 16:39 GMT
Obviously, the code worked for me.

Do you have events disabled?

If so, use this macro:

Sub ReEnable()
Application.EnableEvents = True
End Sub

Did you put the code into a regular code module or into the window that appeared when you r-clicked
and chose "View Code"?

HTH,
Bernie
MS Excel MVP

> On Sep 10, 10:58 am, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
> wrote:
[quoted text clipped - 50 lines]
>
> Sargum
sargum@umich.edu - 10 Sep 2007 17:12 GMT
On Sep 10, 11:39 am, "Bernie Deitrick" <deitbe @ consumer dot org>
wrote:
> Obviously, the code worked for me.
>
[quoted text clipped - 70 lines]
>
> - Show quoted text -

Hi all,

Still have had no luck getting the code to work.  Have enabled macros,
changed security level to medium, did right click and choose "view
code" and paste into window.  This is the code I have put in:

Sub ReEnable()
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Calculate()
'rem Code created by Debra Dalgleish
'modified by Roger Govier

 Dim af As AutoFilter
 Dim fFilter As Filter
 Dim iFilterCount As Integer

 If ActiveSheet.AutoFilterMode Then
' additional lines of code inserted here

 Set af = ActiveSheet.AutoFilter
   iFilterCount = 0
   For Each fFilter In af.Filters
     If fFilter.On Then iFilterCount = iFilterCount + 1
   Next

 If iFilterCount > 1 Then
 Rows(1).EntireRow.Interior.ColorIndex = xlNone
 ActiveSheet.ShowAllData
 Exit Sub
 End If

'additional lines end here

   Set af = ActiveSheet.AutoFilter
   iFilterCount = 1
   For Each fFilter In af.Filters
     If fFilter.On Then
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = 6
     Else
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = xlNone
     End If
     iFilterCount = iFilterCount + 1
   Next fFilter
 Else
   Rows(1).EntireRow.Interior.ColorIndex = xlNone
 End If
End Sub
Roger Govier - 10 Sep 2007 18:03 GMT
Hi

The code (both Debra's original, and my modified) works fine for me.

As Bernie says, are you sure that you have pasted into the Sheet, and not in
a regular module.
In the immediate window of the VBE (press Control+G if it is not visible)
type
Application.EnableEvents = True and then press Enter

Click back to your sheet, and see if it works for you then.

If you are still having a problem, send me an email, and I will post the
file to you.
Send to
roger at technology4u dot co dot uk
Do the obvious thing with dot and at.
Signature

Regards
Roger Govier

> On Sep 10, 11:39 am, "Bernie Deitrick" <deitbe @ consumer dot org>
> wrote:
[quoted text clipped - 137 lines]
>  End If
> End Sub
sargum@umich.edu - 10 Sep 2007 18:39 GMT
On Sep 10, 1:03 pm, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
wrote:
> Hi
>
[quoted text clipped - 164 lines]
>
> - Show quoted text -

I have sent you an abridged version of the file.

thanks.

Sargum
sargum@gmail.com - 10 Sep 2007 21:19 GMT
On Sep 10, 1:39 pm, sar...@umich.edu wrote:
> On Sep 10, 1:03 pm, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
> wrote:
[quoted text clipped - 175 lines]
>
> - Show quoted text -

Hello,

I would like to attach my Excel file to this group so that you may
troubleshoot why I can not run the code...how do I do this?  I had
done this many years ago but can not recall the steps.

Sargum
sargum@gmail.com - 10 Sep 2007 21:25 GMT
On Sep 10, 4:19 pm, sar...@gmail.com wrote:
> On Sep 10, 1:39 pm, sar...@umich.edu wrote:
>
[quoted text clipped - 187 lines]
>
> - Show quoted text -

I noticed that Roger posted an http:/ link, how do I?

S
Peo Sjoblom - 10 Sep 2007 22:15 GMT
>> Hello,
>>
[quoted text clipped - 7 lines]
>
> I noticed that Roger posted an http:/ link, how do I?

1. Don't ever post a file to a non binary newsgroup.
2. Trim your posts if you are going to bottom post
3. Roger offered graciously to receive the file via email from you

Signature

Regards,

Peo Sjoblom

Roger Govier - 10 Sep 2007 22:15 GMT
Hi Sargum

No file arrived. I will check my mailbox again in the morning.

You cannot upload files to this NG. Most people will not open any attached
files.

Signature

Regards
Roger Govier

>> - Show quoted text -
>
[quoted text clipped - 3 lines]
>
> Sargum
sargum@umich.edu - 11 Sep 2007 18:31 GMT
On Sep 10, 5:15 pm, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
wrote:
> Hi Sargum
>
[quoted text clipped - 16 lines]
>
> - Show quoted text -

Hello,

I appreciate the help.  I understand now that I can not post to this
site.  However, I still do not know how to send my file to anyone.
When I click "reply to author" there is no attachment link option.
Also, I have been uable to decipher Roger's email address and have
sent him mine via the "reply to author" but have have not seen an
email from him.  Roger, if you are out there...plz reply to my email
so then I can send you my file to review.  Thx.

Sargum
Bernie Deitrick - 11 Sep 2007 18:47 GMT
roger at technology4u dot co dot uk

Take out all the spaces, change the at to an @ and change the dot to .

This at that dot who dot where

becomes

This@that.who.where

The same is true for my email...

HTH,
Bernie
MS Excel MVP

> On Sep 10, 5:15 pm, "Roger Govier" <rogerattechnology4NOSPAMu.co.uk>
> wrote:
[quoted text clipped - 30 lines]
>
> Sargum
sargum@umich.edu - 11 Sep 2007 19:35 GMT
On Sep 11, 1:47 pm, "Bernie Deitrick" <deitbe @ consumer dot org>
wrote:
> roger at technology4u dot co dot uk
>
[quoted text clipped - 49 lines]
>
> - Show quoted text -

Oh!  Thanks.

Sargum
Roger Govier - 12 Sep 2007 00:13 GMT
Hi Sargum

File received, corrected and returned.
The main problem was that you had failed to include a cell on the sheet with
the volatile formula
= TODAY()
as per Debra's original instruction.

It is the volatility of that formula which triggers the Calculate event code
on the sheet.
I added the formula to cell V1 of your sheet.
The content can be hidden if required by setting the format of cell V1 to be
White font on a white background.

I added a few more rows to your data, with "X's" in dfieefernt locations in
the column to allow a selection of X on the dropdown, which did not include
all rows. As soon as you try to make another selection, the first selection
is cleared.

Signature

Regards
Roger Govier

sargum@umich.edu - 10 Sep 2007 17:53 GMT
On Sep 10, 11:39 am, "Bernie Deitrick" <deitbe @ consumer dot org>
wrote:
> Obviously, the code worked for me.
>
[quoted text clipped - 70 lines]
>
> - Show quoted text -

Hi,

I have macros enabled, my security set to medium, and pasted in "View
Code" window and still nothing seems to have been implemented. Does
anyone have any ideas?   I had put in the following code:

Sub ReEnable()
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Calculate()
'rem Code created by Debra Dalgleish
'modified by Roger Govier

 Dim af As AutoFilter
 Dim fFilter As Filter
 Dim iFilterCount As Integer

 If ActiveSheet.AutoFilterMode Then
' additional lines of code inserted here

 Set af = ActiveSheet.AutoFilter
   iFilterCount = 0
   For Each fFilter In af.Filters
     If fFilter.On Then iFilterCount = iFilterCount + 1
   Next

 If iFilterCount > 1 Then
 Rows(1).EntireRow.Interior.ColorIndex = xlNone
 ActiveSheet.ShowAllData
 Exit Sub
 End If

'additional lines end here

   Set af = ActiveSheet.AutoFilter
   iFilterCount = 1
   For Each fFilter In af.Filters
     If fFilter.On Then
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = 6
     Else
       af.Range.Cells(1, iFilterCount) _
         .Interior.ColorIndex = xlNone
     End If
     iFilterCount = iFilterCount + 1
   Next fFilter
 Else
   Rows(1).EntireRow.Interior.ColorIndex = xlNone
 End If
End Sub

Sargum
manleyhousehold@gmail.com - 13 Sep 2007 22:28 GMT
On Sep 10, 12:53 pm, sar...@umich.edu wrote:
> On Sep 10, 11:39 am, "Bernie Deitrick" <deitbe @ consumer dot org>
> wrote:
[quoted text clipped - 128 lines]
>
> - Show quoted text -

Hello All,

Roger informed me that:

"The underlying problem however, was that you didn't include a cell
with the volatile formula =TODAY() as in Debra's original code.

I added that to cell  V1.

It is essential, as the volatility of the function is what triggers
the Calculate event code for the sheet. Without it, nothing happens.

If you don't want the value to show up, set the format of V1 to be
white text, and it will not show against a white background."

So, now the code works.  Thanks so much for all of your efforts!

Sargum
 
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.