LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Improving Workbook_SheetSelectionChange for enhanced Autofiltering


Dear Community,

I have coded an enhanced Autofilter algorithm that provides improved
funtionality for Autofilter users. Hopefully, I have not replicated
existing work in Excel.

I seem to have a problem with the event handler. Essentially, the row
above the Autofilter header now becomes a field to define criteria.
Essentially, the problem lies with the event
Workbook_SheetSelectionChange not activating upon a change to the cell.
This means that you need to revisit the cell for the macro to perform
its work.

All the code has been included. This resides in the ThisWorkbook
object. Improvements and fixes would be very much apprciated.

Alberto


Code:
--------------------

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

If ActiveSheet.AutoFilterMode Then

Dim af As AutoFilter
Set af = ActiveSheet.AutoFilter

Dim afCols As Integer
afCols = af.Range.Columns.Count

Dim afStart As Range
Set afStart = af.Range(1, 1)

If Target.Count = 1 Then
If InRange(Target, Range(afStart.Offset(-1, 0), afStart.Offset(-1, afCols - 1))) Then
If Target = "" Then
Selection.AutoFilter Field:=(Target.Column - afStart.Column + 1)
Else
searchPattern = Target
If Left(Target, 1) < "<" And Left(Target, 1) < "" And Left(Target, 1) < "=" Then
searchPattern = searchPattern & "*"
End If
Selection.AutoFilter Field:=(Target.Column - afStart.Column + 1), Criteria1:=searchPattern
End If 'NullTarget
End If 'InRange
End If 'Just One cell selected
End If 'AutoFilterMode
End Sub


Private Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
Dim InterSectRange As Range
Set InterSectRange = Application.Intersect(Range1, Range2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
End Function

--------------------


--
aafraga
------------------------------------------------------------------------
aafraga's Profile: http://www.excelforum.com/member.php...o&userid=31314
View this thread: http://www.excelforum.com/showthread...hreadid=531447

 
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
SUMPRODUCT - enhanced formula carol Excel Discussion (Misc queries) 1 July 21st 08 04:05 PM
Enhanced lottery question Brad Excel Discussion (Misc queries) 5 April 18th 08 07:21 PM
Pasting from xl into word as an enhanced metafile LB[_2_] Excel Discussion (Misc queries) 0 April 23rd 07 06:12 PM
enhanced conditional formatting Stuart Excel Discussion (Misc queries) 13 November 13th 05 07:20 PM
Workbook_SheetSelectionChange R.VENKATARAMAN Excel Programming 3 January 23rd 05 11:44 AM


All times are GMT +1. The time now is 03:34 AM.

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"