Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default What was selected in autofilter

Hi, i want to know, how to achieve what was selected in autofilter in row 5
via VBA code and than trigger a code. Thanks.

Henrich
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default What was selected in autofilter

This function returns the filter value

Public Function ShowFilter(rng As Range)
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet

Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range

If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Henrich" wrote in message
...
Hi, i want to know, how to achieve what was selected in autofilter in row

5
via VBA code and than trigger a code. Thanks.

Henrich



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default What was selected in autofilter

Bob,

PERFECT JOB, but one more question. Why the result beginns with '=', like
=Name and not just only Name?

Thanks

Henrich

€žBob Phillips" napĂ*sal (napĂ*sala):

This function returns the filter value

Public Function ShowFilter(rng As Range)
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet

Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range

If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Henrich" wrote in message
...
Hi, i want to know, how to achieve what was selected in autofilter in row

5
via VBA code and than trigger a code. Thanks.

Henrich




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default What was selected in autofilter

because you could be filtering for equals, greater than, less than etc. so
it includes the operator.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Henrich" wrote in message
...
Bob,

PERFECT JOB, but one more question. Why the result beginns with '=', like
=Name and not just only Name?

Thanks

Henrich

"Bob Phillips" napísal (napísala):

This function returns the filter value

Public Function ShowFilter(rng As Range)
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet

Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range

If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Henrich" wrote in message
...
Hi, i want to know, how to achieve what was selected in autofilter in

row
5
via VBA code and than trigger a code. Thanks.

Henrich






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
function to reference value selected with autofilter cm Excel Worksheet Functions 2 September 16th 09 04:56 AM
Autofilter - =string in selected cell al007 Excel Programming 3 December 1st 05 04:37 PM
Why does AutoFilter display rows NOT selected from drop down box? Jo M Excel Discussion (Misc queries) 9 October 15th 05 01:08 AM
Autofilter selected arrow color Jon Quixley Excel Worksheet Functions 1 August 2nd 05 11:56 AM
Find out what is selected for AutoFilter Dan Excel Programming 1 July 20th 05 05:21 PM


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