VBA Filter

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

Is there a way to define the Criteria1:=Array so that it shows all items except the ones you define? So how would i define the array if i wanted to show all values except Apple, Oranges, Pears?

Thanks!
 
It should be
Code:
Set FilterRange = Range("A2[COLOR=#ff0000]:A[/COLOR]" & lastRow2)
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
DOH! Thanks again!! I forgot that a range needs a starting cell, then the column and last row.
How come .show doesn't work on the last code? wondering how i would change the code to show the values in the array instead of hiding them.
 
Upvote 0
There is no such thing as .Show for a dictionary.
What the code is doing is adding all unique values from col B into a dictionary & then removing the values from your "list".
The resulting array is then used to filter the data for everything but the values in your list
 
Upvote 0
how would you do the opposite? so instead of filtering out everything in the list, it would filter (show) everything in the list?
 
Upvote 0
Simply plug the list into the filter
 
Upvote 0
@Fluff are you able to help interpret how exactly this works? I love using it, but i really don't know how it works and how i would manipulate it to work in other scenarios?

Set ws3= ThisWorkbook.Worksheets("Sheet3")
Set ws1 = ThisWorkbook.Worksheets("Sheet1")


Dim lastrow, lastrow2, i As Long
Dim Searchfor, j, inarr As Variant


With ws1
lastrow = .Cells(Rows.Count, "G").End(xlUp).Row
inarr = Range(.Cells(3, 1), .Cells(lastrow, 18))
End With


With ws3
lastrow2 = .Cells(Rows.Count, "G").End(xlUp).Row
searcharr = Range(.Cells(3, 7), .Cells(lastrow2, 7))
outarr = Range(.Cells(3, 1), .Cells(lastrow2, 18))
End With


On Error Resume Next
For i = 3 To lastrow2
For j = 3 To lastrow
Searchfor = searcharr(i, 1)
If inarr(j, 1) = Searchfor Then
For kk = 1 To 18
outarr(i, kk - 1) = inarr(j, kk)
Next kk
Exit For
End If
Next j
Next i


With ws1
Range(.Cells(3, 1), .Cells(lastrow2, 18)) = outarr
End With
 
Upvote 0
As this is a totally different question, please start a new thread.
 
Upvote 0
@Fluff I've been playing around this this code and i'm still stuck with "Simply plug the list into the filter". What does that mean?


Also, if i have multiple lists and want to use a validation drop down to determine which list to compare how would i make "list" below dependent on the entry. I have defined all of the ranges, just not sure how to use them.

For Each cl In "LIST"

Thanks!!
 
Upvote 0
"Simply plug the list into the filter". What does that mean?
If you have an array of Apples, Pears oranges.You use that array in the autofilter.
As for the rest of your question. Please start a new thread, as this is different from the OP
 
Upvote 0
Sorry for being a little slow on the uptake here, but I don't know which array to put in the autofilter.

This currently compares List A with List B and removes the List B items from List A. I would like to remove the items not on List B from List A. I tried swapping them in this code, but it didn't work.

Thanks!

With CreateObject("scripting.dictionary")
For Each cl In ListA
.Item(cl.Value) = Empty
Next cl
For Each cl In ListB
If .exists(cl.Value) Then .Remove cl.Value
Next cl
ListA.AutoFilter 1, .keys, xlFilterValues
End With
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top