Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Filter Function

can someone post an example of the Filter Function in VB.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Filter Function

David,

If you check out this previous post, you will see an example of creating a
column to test a value, filtering on that value, and then deleting the
filtered rows. Hopefully it will show you what you want

http://tinyurl.com/v4qk

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Robinson" wrote in message
...
can someone post an example of the Filter Function in VB.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Filter Function

Here's one:

Sub VBAFilterExample()

'Criteria used in search. Change as desired
Const szCRITERIA As String = "rob"

Dim lCount As Long
Dim vOrigArray As Variant
Dim vFilterArray As Variant
Dim szMsgOrig As String, szMsgFilter As String

'Create an array
vOrigArray = Array("Robert", "Rob", "Mac", "Bert", "Sam")

'Store the contents of the array in a string for later use
For lCount = LBound(vOrigArray) To UBound(vOrigArray)
szMsgOrig = szMsgOrig & vOrigArray(lCount) & ", "
Next lCount

'Filter the array based on the criteria. The result is another Array
with just the filtered results
'Note: True = retrieve all that match the criteria. False = retrieve all
that DON'T match the criteria
vFilterArray = Filter(vOrigArray, szCRITERIA, True, vbTextCompare)

'Store the contents of the new filtered array in a string for later use
For lCount = LBound(vFilterArray) To UBound(vFilterArray)
szMsgFilter = szMsgFilter & vFilterArray(lCount) & ", "
Next lCount

'Show the original array, the criteria, and the filtered (resulting)
array in a Message Box
MsgBox "Original Array: " & szMsgOrig & vbLf & vbLf & "Criteria: " &
szCRITERIA & vbLf & vbLf & "Resulting Array: " & szMsgFilter, vbInformation,
"Filter Function Example"
End Sub
_______________________
Robert Rosenberg
R-COR Consulting Services
Microsoft MVP - Excel

"David Robinson" wrote in message
...
can someone post an example of the Filter Function in VB.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Filter Function

Sub Tester1()
varr = Array("ABCD", "ADCE", "BCDA", "1234", "ECDA")
varr1 = Filter(varr, "BC", True, vbTextCompare)
For i = LBound(varr1) To UBound(varr1)
Debug.Print varr1(i)
Next
End Sub

--
Regards,
Tom Ogilvy


David Robinson wrote in message
...
can someone post an example of the Filter Function in VB.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Filter Function

Dear Bob

Actually I was referring to a function I just found in
the help screen which "Returns a zero-based array
containing subset of a string array based on a specified
filter criteria". Any example of this:

Filter(sourcesrray, match[, include[, compare]])

David

-----Original Message-----
David,

If you check out this previous post, you will see an

example of creating a
column to test a value, filtering on that value, and

then deleting the
filtered rows. Hopefully it will show you what you want

http://tinyurl.com/v4qk

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Robinson"

wrote in message
...
can someone post an example of the Filter Function in

VB.


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Filter Function


Thankyou for this Tom

Can I get this to work on multidimensional arrays?

-----Original Message-----
Sub Tester1()
varr = Array("ABCD", "ADCE", "BCDA", "1234", "ECDA")
varr1 = Filter(varr, "BC", True, vbTextCompare)
For i = LBound(varr1) To UBound(varr1)
Debug.Print varr1(i)
Next
End Sub

--
Regards,
Tom Ogilvy


David Robinson

wrote in message
...
can someone post an example of the Filter Function in

VB.


.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Filter Function

Not directly. The help on filter cites sourcearray (the first argument) as a
one dimensional array of strings.

While you could program around this to extract the filter column, use filter
to build an array of those row "indexes" that meet the criteria and so
forth, it might be just as easy to go through your array and do a simple if
test - then put each matching row in another array.

--
Regards,
Tom Ogilvy


wrote in message
...

Thankyou for this Tom

Can I get this to work on multidimensional arrays?

-----Original Message-----
Sub Tester1()
varr = Array("ABCD", "ADCE", "BCDA", "1234", "ECDA")
varr1 = Filter(varr, "BC", True, vbTextCompare)
For i = LBound(varr1) To UBound(varr1)
Debug.Print varr1(i)
Next
End Sub

--
Regards,
Tom Ogilvy


David Robinson

wrote in message
...
can someone post an example of the Filter Function in

VB.


.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Filter Function

Just two cents. I have never gotten this function to filter out blank
strings. This mostly occurs when placing a column of data from the
worksheet into an array. I have tried everything imaginable in the past.
Does anyone know if this "feature" to filter out blank strings was added in
Excel 2003?

Sub Wont_Work_in_Xp()
Dim v
v = Array("ABCD", "ADCE", "", "1234", "ECDA")
v = Filter(v, "", False, vbTextCompare)
End Sub

Returns an empty array.


If one does not like the zero based returned array, here is a technique to
turn it back into a 1-based array.

Sub Demo()
Dim v
Dim v_ZeroBased
Dim v_OneBased

v = Array("ABCD", "ADCE", "BCDA", "1234", "ECDA")
v_ZeroBased = Filter(v, "BC", True, vbTextCompare)

With WorksheetFunction
v_OneBased = .Transpose(.Transpose(v_ZeroBased))
End With
End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"David Robinson" wrote in message
...
can someone post an example of the Filter Function in VB.



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
SUM while using filter function KenCanuck Excel Discussion (Misc queries) 1 March 19th 09 10:53 PM
HELP - filter function Idaho Excel User Excel Discussion (Misc queries) 1 August 24th 06 04:18 PM
Advanced Filter Function carl Excel Worksheet Functions 1 May 25th 06 05:17 PM
Filter function Brian Brandt Excel Worksheet Functions 5 April 26th 06 12:59 PM
filter function Johannes van der Pol Excel Worksheet Functions 6 November 24th 04 12:53 PM


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