Apply filter on the basis of multiple values

Tejas Kore

Board Regular
Joined
Nov 2, 2017
Messages
72
Office Version
  1. 365
Platform
  1. Windows
I have this data .
CountryName
IndiaA
IndiaB
IndiaC
AustraliaD
AustraliaE
PeruF
PeruG
ChileH
ChileI

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

Now I want to apply filter to this data in such a way that India And Australia comes in one category and Peru And Chile comes in another.
Right now I have the code to split this file in 4 files , each one corresponding to one country.
How can I apply multiple search criteria to Column A which is the column containing Countries ?

Here is the code :

Sub Sample()


Dim wswb As String
Dim wssh As String


wswb = ActiveWorkbook.Name
wssh = ActiveSheet.Name


vcolumn = InputBox("Please indicate which column,you would like to split by", "Column Selection")
Columns(vcolumn).Copy
Sheets.Add
ActiveSheet.Name = "_Summary"
Range("A1").PasteSpecial
Columns("A").RemoveDuplicates Columns:=1, Header:=xlYes
vCounter = Range("A" & Rows.Count).End(xlUp).Row


For i = 2 To vCounter
vfilter = Sheets("_Summary").Cells(i, 1)
Sheets(wssh).Activate
ActiveSheet.Columns.AutoFilter field:=Columns(vcolumn).Column, Criteria1:=vfilter
Cells.Copy
Workbooks.Add
Range("A1").PasteSpecial
If vfilter <> "" Then
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\split results" & vfilter
Else
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\split results\_Empty"
End If
ActiveWorkbook.Close
Workbooks(wswb).Activate


Next i


Cells.AutoFilter
Application.DisplayAlerts = False
Sheets("_Summary").Delete


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub F()
    With Range("A1").CurrentRegion
        .AutoFilter Field:=1, Criteria1:=Array("India", "Australia"), Operator:=xlFilterValues
        .Copy Sheets.Add().Cells(1)
    End With
End Sub
 
Upvote 0
code deleted per OP request
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,175
Members
448,870
Latest member
max_pedreira

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