Hi there!
I've all morning trying to resolve this so please help me...
All I need is just to have 3 or more different criterias in an autofilter.
I tried this but it wont work...
please give a hand!
Thanks!
Code:Dim a, b, c, a1, b1, c1 As String a = Cells(5, 17).Value b = Cells(6, 17).Value c = Cells(7, 17).Value a1 = Cells(5, 18).Value b1 = Cells(6, 18).Value c1 = Cells(7, 18).Value .... ActiveSheet.Range("$A$4:$N$15132").AutoFilter Field:=1, Criteria1:=a, Operator:=xlOr, Criteria2:=b, Operator:=xlOr, Criteria3:=c ActiveSheet.Range("$A$4:$N$15132").AutoFilter Field:=3, Criteria1:=a1, Operator:=xlOr, Criteria2:=b1, Operator:=xlOr, Criteria3:=c1
Last edited by royUK; 03-20-2010 at 11:51 AM. Reason: add code tags
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
Code Tags added this time
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Please tell why this works
and this doesn'tCode:ActiveSheet.Range("$A$4:$N$15131").AutoFilter Field:=1, Criteria1:=Array("154", "155", "156", "157"), Operator:=xlFilterValues
Code:Dim a, b, c, d As String a = 154 b = 155 c = 156 d = 157 ActiveSheet.Range("$A$4:$N$15131").AutoFilter Field:=1, Criteria1:=Array(a, b, c, d), Operator:=xlFilterValues
Your dim statement has only declared variable d as a string. In the absence of a variable type, the variant type is used by default. This means that a, b and c behave like integers.
Try using
Code:Dim a As String, b As String, c As String, d As String
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
Excel versions prior to 2007 only support two criteria and arrays, as far as I know, cannot be used within Auto-Filter. Don't have Excel 2007 on this PC, so, not sure if it accepts use of arrays - but it does support many more criteria than prior versions.
If the array approach does not work, it would be quite simple and just as efficient to pass the string variables into a range of cells and specify that range as criteria for Advanced Filter.
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
hi Machado,
Welcome to the forum
I think you should have put this post in your previous thread because it seems to be the same issue to me. Hopefully a Mod will spot this & they can merge the two threads...
Edit: My connection's playing up today (again!) so I'm sorry about the double up of info - see Martin's previous post for the same comments about your variable declarations. /end edit.
I couldn't see any relevant* information in either the VBE or Excel's 2007 Help files for Autofilter but perhaps the following may help...
*Unless, do you have a mixture of formats in the column to be filtered (eg string & number)?
If you need more than two criteria, as you've mentioned in the previous thread, then I suggest you use a Helper column containing a formula which returns a True or False (perhaps an If statement) if any of the criteria are fulfilled.Code:Dim a, b, c, d As String 'the above line of code is the equivalent of the below Dim a as variant, b as variant, c as variant, d As String 'when I think your intent is more along the lines of... Dim a As String, b As String, c As String, d As String
hth
Rob
Last edited by broro183; 03-20-2010 at 02:07 PM.
Rob Brockett
Kiwi in the UK
Always learning & the best way to learn is to experience...
Thanks!!!!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks