VBA: Filter Data with Multiple Values

VBA: Filter Data with Multiple Values

PK: An Excel Expert

5 лет назад

89,299 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ashishagrawal9431
@ashishagrawal9431 - 17.10.2023 18:30

Thank you. How to restrict only selected column to be copied in Output sheet. I need only few columns in the output. how vba query should be adjusted

Ответить
@salahlechekhab6433
@salahlechekhab6433 - 12.09.2023 16:42

hello, thank you , i need filtred by years in output exemple: 2018-2019-2020

Ответить
@Andrea-yc2jp
@Andrea-yc2jp - 30.12.2022 16:29

Thanks!
I have only one problem:
I have a table where there are empty cells and the filter is hiding all the rows which don't contain the complete data.

Example:
In a table with headers "Date, Description, Category, Amount, Notes", when i search "Food" the filter doens't show the rows in which the "Notes" cell is empty.

How can I make the filter also show me rows with some empty cells?

Ответить
@cia120
@cia120 - 10.10.2022 20:15

how criteria is contain , not equal?

Ответить
@Calabrel
@Calabrel - 04.10.2022 17:11

This VBA script worked great. Thank you for the video.

Question, if you wanted to invert the filtered data so that you copy/paste the data that isn't listed in your Filter_Criteria_Sh, how would you go about doing that?

It would be very beneficial to be able to exclude things I want to copy with a list.

Ответить
@juliussamaniego1741
@juliussamaniego1741 - 19.07.2022 04:34

Thanks a lot! You have no idea how this video has helped me! Thank you, you're a crack!!

Ответить
@cindymesia401
@cindymesia401 - 22.06.2022 12:20

Option Explicit


Sub Filter_Criteria()

Dim Data_sh As Worksheet
Dim Filter_Criteria_Sh As Worksheet
Dim Output_sh As Worksheet

Set Data_sh = ThisWorkbook.Sheets("Data")
Set Filter_Criteria_Sh = ThisWorkbook.Sheets("Filter_Criteria")
Set Output_sh = ThisWorkbook.Sheets("Output")

Output_sh.UsedRange.Clear

Data_sh.AutoFilterMode = False

Dim Emp_list() As String
Dim n As Integer

n = Application.WorksheetFunction.CountA(Filter_Criteria_Sh.Range("A:A")) - 2

ReDim Emp_list(n) As String

Dim i As Integer

For i = 0 To n
Emp_list(i) = Filter_Criteria_Sh.Range("A" & i + 2)
Next i

Data_sh.UsedRange.AutoFilter 2, Emp_list(), xlFilterValues
Data_sh.UsedRange.Copy Filter_Criteria_Sh.Range("c1")
Data_sh.AutoFilterMode = False

End Sub

Ответить
@cindymesia401
@cindymesia401 - 22.06.2022 12:20

sir, what if i filter multiple criteria but its just a keyword not the exact word? how would I do that?

Ответить
@shravanjanagani9216
@shravanjanagani9216 - 06.04.2022 13:50

Thank you❤

Ответить
@nv05
@nv05 - 14.03.2022 22:03

Just wow .bro..thank you

Ответить
@healthyman01
@healthyman01 - 01.02.2022 14:46

It works, but it only return 2 values on output when i search for emp1 and emp2.. if i add the 3rd emp3 it clears the output sheet. Any idea wc part of code to fix? Tnx.

Ответить
@Achiuce
@Achiuce - 11.11.2021 00:10

how to let VBA allow to return a normal range if the criteria is empty? I'm trying to implement such a system for an entire database. If I don't want to put a criteria under one field. I still want it to return the ones I have inputted cells to. Any help is much appreciated

Ответить
@ankit143dolly
@ankit143dolly - 01.11.2021 10:24

Hi, M getting error of autofilter method of range class failed. Pl suggest

Ответить
@surajdalvi3437
@surajdalvi3437 - 26.10.2021 12:27

Can you please help here, I am not able to copy filter data in output. All data is getting pasted in output sheet. I am using same code

Ответить
@surajdalvi3437
@surajdalvi3437 - 25.10.2021 19:40

That's great 👍

Ответить
@aniketbhalerao8097
@aniketbhalerao8097 - 21.09.2021 13:22

PK thanks a lot, speed is perfect not too slow not too fast, easily explained functions. :)

Ответить
@samirstatuscreation3028
@samirstatuscreation3028 - 03.08.2021 13:54

Hi Sir,

Me aapka Subscriber Hu muje aapke saare videos ache lge muje aapse ek help chahiye thi

Aapki is video me hai viase hi muje krna hai bat thodi dikkat aa rahi hai . Muje har ek value ex. Emp ko filetr kar iski kuch values copy krni hai har emp ki alag alg range hogi ex. Kisi emp ki fist 2 to kisi ki 5 aise sabki alag alg par meri define ki huvi range ki value chahiye or ye code har ek emp me run krvana hai
Sir please help and solve this

Your Subscriber,
Samir Kagda

Ответить
@hindubrahman768
@hindubrahman768 - 28.06.2021 14:26

Fantastic Work done by you

Ответить
@jagritbhagat9529
@jagritbhagat9529 - 26.06.2021 12:55

Very nice video👍

Ответить
@ghuskia
@ghuskia - 28.05.2021 07:26

Excellent.. Thank you.. Please make more of it on vba pivot table

Ответить
@tejsinghsarangdevot8198
@tejsinghsarangdevot8198 - 24.05.2021 05:58

I have write

Option Explicit

Sub Filter_Cult()
Dim sht2 As Worksheet
Dim Sht1 As Worksheet

Set sht2 = ThisWorkbook.Sheets("Sheet2")
Set Sht1 = ThisWorkbook.Sheets("Sheet1")



sht2.AutoFilterMode = False
sht2.UsedRange.AutoFilter 1, Criteria1:=Sht1.Range("B1")
sht2.UsedRange.AutoFilter 7, Criteria2:=Sht1.Range("B2")
End Sub


but i have want

if Criteria1:=Sht1.Range("B1") B1="ALL"
sht2.UsedRange.AutoFilter 1, SHOW ALL DATA

if Criteria2:=Sht1.Range("B2") B2="ALL"
sht2.UsedRange.AutoFilter 7, SHOW ALL DATA

Ответить
@biplabbaishnab3926
@biplabbaishnab3926 - 27.04.2021 12:10

Ended my search on filtering here. Well explained brother, keep going

Ответить
@1668hk
@1668hk - 01.02.2021 06:50

again well done !

Ответить
@erdiaz39
@erdiaz39 - 22.12.2020 00:55

AWESOME PK!!!!!!!!!!!!!! You are my HERO!!!!!!

Ответить
@balukasagani2003
@balukasagani2003 - 16.10.2020 16:43

instead of all the columns,I want to copy only few columns data from Data tab to output tab, is that possible ?

Ответить
@AniManuSCh
@AniManuSCh - 21.09.2020 20:39

How about the criteria being in the same cell?

Ответить
@Sasha_5M
@Sasha_5M - 29.08.2020 11:39

I am searching many times but could not find any relevant videos....now i just wanted to know that you have given criteria only for 3 rows but how we can do it by putting many line items in criteria...will criteria automatically select ? or we need to change the criteria every time ?

Ответить
@srinivasv8842
@srinivasv8842 - 28.08.2020 15:48

Hi, I am unable to filter using criteria *value using vba. Please share your thoughts am using Excel 2013

Ответить
@swamydadi5887
@swamydadi5887 - 21.08.2020 01:48

Thanks a lot...
It Helped me a lot.

Ответить
@chintamanishisode7553
@chintamanishisode7553 - 13.08.2020 18:39

If one of criteria is not available then it will fail ?

Ответить
@tomasvolockis3935
@tomasvolockis3935 - 15.07.2020 16:40

Just what i needed, thank you Sir !

Ответить
@asifattar8158
@asifattar8158 - 09.07.2020 14:43

Thanks PK. I tried the same code. However, ReDim is not working. Run-time error 9. Subscript out of range. Could you please help on this.

Ответить
@l1989
@l1989 - 29.06.2020 15:14

Thanks 😊☺️

Ответить
@btyz16
@btyz16 - 23.06.2020 17:26

Hi, How can i find the row number of filtered the data ? I want to edit some of filtered cells.

Ответить
@VinodKumar-yp8gd
@VinodKumar-yp8gd - 05.05.2020 08:55

How to filter based on header name as we are giving autofilter field may be 2 or 3 column numb instead i want to give autofilter field as name ( header name) of the column

Can u pls help me its a real problem i stuck with as my input data's header kept shuffling often

Ответить
@MARQUITOSGUALACBA
@MARQUITOSGUALACBA - 15.04.2020 04:51

how can I get the first field in a column after the filter?

Ответить
@Immortal34345
@Immortal34345 - 30.03.2020 20:44

Please need your help.. I added ur macros.. But it gives only values with numbers, is there any way to make it get data, numbers text or whatever

Ответить
@maheshnelapati7930
@maheshnelapati7930 - 26.03.2020 12:50

At a time

Ответить
@maheshnelapati7930
@maheshnelapati7930 - 26.03.2020 12:49

Hi PK, Excellent video, I have a doubt, I want pass input at a tie from multiple fields of Filter
_Criteria sheet to data sheet to filter . And the filtered data I want to paste in to Output sheet.Could you please tell me how to do that

Ответить
@rakeshbond009
@rakeshbond009 - 22.03.2020 13:50

How to filter numbers

Ответить
@Pankaj-Verma-
@Pankaj-Verma- - 10.03.2020 19:06

Thank you for your kind help.

Ответить
@GerryStilton
@GerryStilton - 10.02.2020 02:54

Just what I needed. Thanks PK! I thought autofilter syntax, the ARRAY was for the Excel formula Array rather than the vba array data structure type. That cleared it up.

Ответить
@RajeshwarUma
@RajeshwarUma - 20.12.2019 11:14

Ok it's very interesting but I need data sheet another column random values of employees records only that s records only one one copy could help me

Ответить
@shahir051
@shahir051 - 13.12.2019 19:48

Dear PK,
Excellent presentation
Really helped
Thank you very much

Expecting many more videos like this...

Ответить
@denverjamesduran2750
@denverjamesduran2750 - 10.12.2019 17:35

Thank you I was searching the whole web for this!

Ответить
@RajKumar-dg6kv
@RajKumar-dg6kv - 09.10.2019 19:12

I need to filter using data from activecell.. for example if I click a particular cell in sheet 1 that value should be filtered in sheet 2

Ответить
@elguensamaritano
@elguensamaritano - 01.10.2019 19:48

this men deserve a very special place on haven, you make a great work thanks

Ответить
@gregandcindylaporte4479
@gregandcindylaporte4479 - 24.09.2019 04:26

Hello, your video is very straight to the point and I will use most of the coding. However, i need some help around the Filter table section. I do not want to "hard code" it. I want to Copy a value from one cell on another sheet and paste it on the Auto Filter criteria. Any thoughts or links you may have?

Ответить
@katarinalabanova7178
@katarinalabanova7178 - 19.08.2019 20:27

Hi! Thanks for very useful video. I am  interested how can I adjust macro to copy filtred range to output without headings (first row)? Could you please advise?

Ответить