Excel VBA Macro: Autofilter Based on Cell Value (Step-by-Step Tutorial)

  Рет қаралды 72,489

greggowaffles

greggowaffles

Күн бұрын

Пікірлер: 99
@greggowaffles
@greggowaffles 3 жыл бұрын
Autofilter Based on Multiple Cell Values! 😎😎 kzbin.info/www/bejne/f4bLZXlvaNuterM
@wollebooy
@wollebooy 2 жыл бұрын
i have tried to follow you video, step by step. When i run the macro, i got a 1004 runtime Error. Can you tell me why i experince this issue?
@praiserofthesun3645
@praiserofthesun3645 4 ай бұрын
5 years later and you saved my ass just because I actually forgot how to do this bs, thanks a lot man
@greggowaffles
@greggowaffles 4 ай бұрын
Anytime! 😎
@thomasrusli1934
@thomasrusli1934 4 ай бұрын
Hello, how about filter based on specific value in the cell, for the example the value is "Amer", so the data will be show as Northern America, Latin Amer & Carib, etc
@lanceross1035
@lanceross1035 6 ай бұрын
Helpful video. I didn't realize at first why Field was 2, but figure it out. You present well.
@greggowaffles
@greggowaffles 6 ай бұрын
Appreciate that!
@palamentor7008
@palamentor7008 3 жыл бұрын
Thanks man, I've been working so hard to figure this out, but now with this video and a little bit of customizing, I'm able to have my macro work. Really appreciate it!!!!
@greggowaffles
@greggowaffles 3 жыл бұрын
No prob! Glad to hear that!!
@averybrothers1785
@averybrothers1785 Жыл бұрын
Hello, thanks for the video! Can you explain how to filter on a specific cell that is in another sheet in the same file? I am trying to filter a column in my "report" sheet based on a cell in my "HOME" sheet.
@naomifagan2885
@naomifagan2885 2 жыл бұрын
It’s just not working for me at all says subscript out of range and I can’t figure out why the only thing I’ve changed is column numbers
@Dexter101x
@Dexter101x 10 ай бұрын
More or less of what I wanted to be honest, but is there a way to clear the filter after running this?
@darpananand1302
@darpananand1302 11 күн бұрын
Can you also explain how to auto filter using cell value in different workbook
@darpananand1302
@darpananand1302 11 күн бұрын
Please share VBA code to filter based on cell value in different workbooks. You explained using from different sheet in same workbook but i need VBA code to filter data from cell value present in different workbook.
@bobbygoud5518
@bobbygoud5518 9 күн бұрын
Can you do multiple criteria? I want create a coulmn for user to just enter whatever multiple values in criteria and data to be generated automatically
@greggowaffles
@greggowaffles 5 күн бұрын
Hope this helps! Excel VBA Macro: Autofilter All Values In A List (Dynamic Range) kzbin.info/www/bejne/gmqlmX5secqdrpY
@Drew-vp
@Drew-vp 4 ай бұрын
Hi what if you have a cell with defined name. How can you reference that ?
@ptoricoluv
@ptoricoluv Жыл бұрын
That was great. Easy to follow. Thanks. Is it possible to create a vba to filter a table based on a cell value and another for blanks ?
@greggowaffles
@greggowaffles Жыл бұрын
Thanks! Yeah, definitely
@greggowaffles
@greggowaffles Жыл бұрын
Do you have a specific example? I can make a video on it
@jayganesh1079
@jayganesh1079 3 жыл бұрын
I have made an excel file in which there is macro to hide zero value. If I run the macro, other values (except Zero) will be shown, and then if I again use filter, all the data shows. Any solution?? Any macro for both?
@alejandroesquivelcordero6970
@alejandroesquivelcordero6970 3 жыл бұрын
How can you get a reference to a cell in the first row of filtered data?. For example, you filter those with an area less than 1000 sq. mi. and THEN you need to click on a button that shows all the elements of the region of the first element of that filtered set (but not only those less than 1000 sq.mi.?
@samuelborrero-maldonado6353
@samuelborrero-maldonado6353 3 жыл бұрын
Dude, I am about to break my work computer. I follow everything exactly but for me I get "Expected: End of statement" with the "Field" highlighted. It would greatly help if you had any suggestions on this!! thank you!
@greggowaffles
@greggowaffles 3 жыл бұрын
What’s your code look like?
@josebatoctoy9248
@josebatoctoy9248 3 жыл бұрын
How to filter multiple columns using cell value and can still function even if other values to be filtered is empty?
@simo758
@simo758 4 жыл бұрын
Great video. Can i filter more than a single value? lets say if we have a date for example and i want to filter both date and range. Should i duplicate the Sheet("Sheets).Range etc...?
@greggowaffles
@greggowaffles 4 жыл бұрын
thanks! yes, you can use the line of code from the video twice in the same sub and just change the AutoFilter field and Criteria, so that one cell you reference has the date and the other cell has the range
@prathaprgowda8481
@prathaprgowda8481 2 жыл бұрын
What to do when i have to filter by 2 values (2 or multiple cells values)
@swethakrishnak6093
@swethakrishnak6093 2 жыл бұрын
Hi, how to autofilter date range, for example from 07/07/2022 to 25/08/2022
@dhirajp4677
@dhirajp4677 4 жыл бұрын
It was a nice informative video Gregg..what will be the code if I want to run macro on ENTER key..?
@greggowaffles
@greggowaffles 4 жыл бұрын
thanks! Application.OnKey "{ENTER}"
@RajeshwarUma
@RajeshwarUma 4 жыл бұрын
Thanks so much but I have one question it's supported to 2013 version
@greggowaffles
@greggowaffles 4 жыл бұрын
no problem! yes it's supported.
@mofa1266
@mofa1266 2 жыл бұрын
Please tell how to remove same filters using macro
@brianfrank6968
@brianfrank6968 4 жыл бұрын
It's putting my filter on Row 1 when my data starts in Row4, why? I have the exact same code as you (it's messing up the format and filtering out the header)
@greggowaffles
@greggowaffles 4 жыл бұрын
Is there any data above Row4 at all?
@cindymesia401
@cindymesia401 2 жыл бұрын
sir, what if im gonna search multiple criteria but in keywords is that possible? heres my code that im trying to make: 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
@raulspro
@raulspro 4 жыл бұрын
Thank you so much. It help a lot to a beginner like me. Can you please tell how can I filter 2 or more cell value. As you searched EASTERN EUROPE . but I want to search EASTERN EUROPE, NORTHERN AFRICA & OCEANIA.
@greggowaffles
@greggowaffles 4 жыл бұрын
No problem! Hope this helps: kzbin.info/www/bejne/gmqlmX5secqdrpY
@greyhound2743
@greyhound2743 4 жыл бұрын
This is great - what if the filter value is in another file? Cheers!
@greggowaffles
@greggowaffles 4 жыл бұрын
thanks! you can just reference the file name before "Sheets". apologies for the late reply
@anushiyakp1587
@anushiyakp1587 3 жыл бұрын
How to filter the date based on cell value?
@RJthesoundstreaming
@RJthesoundstreaming 4 жыл бұрын
This vba works really well. Thank you so much for the video. I have one question, is that possible if the cell value can read based on single character or any series of characters (doesn't have to be the same) and use wildcard, for example contains "*" or "?" on the vba code. If possible, how to do so? Is there a way to do that? I need it so much.
@greggowaffles
@greggowaffles 4 жыл бұрын
Thanks! Yup, if you put N* in the cell from the code in the video you'll see Northern Africa, Near East, and Northern America get filtered. Hope that helps!
@RJthesoundstreaming
@RJthesoundstreaming 4 жыл бұрын
Yesssss it helps. Thanks you so much for your reply and assistance. You're amazing.
@greggowaffles
@greggowaffles 4 жыл бұрын
@@RJthesoundstreaming no prob!
@RJthesoundstreaming
@RJthesoundstreaming 4 жыл бұрын
@@greggowaffles hello, I think I wanna ask you something. There are 2 sheets in my Excel workbook: Sheet1: MUFG Client Sheet 2: Company Information So basically I want to do autofilter at MUFG Client sheet in "Keyword" field (Field 29) from another cell (I18) in Company Information sheet. And the content of the cell is the result from vlookup formula so it will change and not always be the same. Here goes my vba code: Sub filter_by_cell_value () Sheets("MUFG Client").Range("A2").Autofilter Field:=29, _ Criteria1:="=*" & Sheets("Company Information").Cells(18,6).Value & "*", xlOperator:= xlOr End Sub My objective is I want the autofilter can read the text in cell I18 without specific text/criteria. For example, if the cell I18 contains Cosmetics, Chemical --> I want the autofilter in Keyword Field can show the word Cosmetics or Chemical, then If I change the content of company information sheet into different company (The result of vlookup), the cell I18 in Company Information will change into Food & Beverage, Business Expansion, FMCG--> And I also want the autofilter in the keyword Field (MUFG Client sheet) shows Food & Beverage or Business Expansion or FMCG (Autofiltering contains those words by ignoring order) And from my vba code above, Cells(18,6) is cell I18 in Company Information Sheet. Is it possible to do so? I think I have to discuss this directly to make you understand. Sorry if this makes misunderstanding. Thank you so much...
@girishankar09
@girishankar09 3 жыл бұрын
@@greggowaffles The video was helpful...My use case is where the cell based criteria is dynamic so I cannot put any character like N* or A* but need to use wildcards to cell value. In the video it shows as "Criterial:= Cells(2, 6).Value". So how can I add * to this so that when ever cell value changes and we run macros, it automatically adds * at the beginning or end of the word in the cell
@pankajnegi8792
@pankajnegi8792 5 жыл бұрын
Thankyou so much. This is what I was looking for.
@greggowaffles
@greggowaffles 5 жыл бұрын
No problem! I'm glad to hear that!!
@frankpartida8685
@frankpartida8685 4 жыл бұрын
Great videos... I've learned a few things by watching your videos, Thanks... I have a question on this. Can this same auto-filter be done based on cell value, but to look in several columns at once without being limited to one column only. In other words, in your example, to be able to type either country or region in cell value and to filter that?... Thanks in advance.
@greggowaffles
@greggowaffles 4 жыл бұрын
thanks, Frank! you can use the line of code from the video twice in the same sub and just change the AutoFilter field and Criteria, so that one cell you reference has the country and the other cell has the region. apologies for the late reply
@LipFung
@LipFung 4 жыл бұрын
@@greggowaffles i have the same question same with Frank Partida. but is it possible to have 2 criteria in 1 cell reference instead of 2?
@greggowaffles
@greggowaffles 4 жыл бұрын
Hey you can try to use an array for that. So you would use Dim arr as Variant and then set arr = cell value. Then use arr as your criteria in your filter
@LipFung
@LipFung 4 жыл бұрын
@@greggowaffles Hi, i managed to type the code suggested by you. unfortunately , the result will show nothing when search the keyword. i believe it cannot filter 2 column at the same time. Anyway, thanks for your help :)
@greggowaffles
@greggowaffles 4 жыл бұрын
No problem!
@Mzert805
@Mzert805 Жыл бұрын
Amazing video!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@greggowaffles
@greggowaffles Жыл бұрын
Thanks!!!
@luisaguilar5758
@luisaguilar5758 3 жыл бұрын
Can you do the same with pivot tables?
@greggowaffles
@greggowaffles 3 жыл бұрын
yup, check this out: www.thespreadsheetguru.com/blog/2014/9/27/vba-guide-excel-pivot-tables
@shanetravel
@shanetravel 3 жыл бұрын
thank you sir!
@greggowaffles
@greggowaffles 3 жыл бұрын
No prob!
@9985235346
@9985235346 5 жыл бұрын
Hi.. I need assistance on screen clipping VBA. Is it possible?
@greggowaffles
@greggowaffles 5 жыл бұрын
Hi Naresh. Yes! You can use VBA and APIs to do it
@liza-mariwright379
@liza-mariwright379 3 жыл бұрын
Hallo! I want to filter a date value, how would I phrase the criteria to have this, it doesn't pick it up as a date. Thanks in advance
@greggowaffles
@greggowaffles 3 жыл бұрын
Hey! You just want to have the criteria in the same format as the date in the column you're filtering. Ex: Criteria1:="7/20/2021"
@liza-mariwright379
@liza-mariwright379 3 жыл бұрын
@@greggowaffles And if that criteria date changes based on the cell value how to I make it see the value is the same? Cell(1,37).value is what you say in the video. How do I change that so that it sees it as a date. Thanks for getting back to me so quickly
@greggowaffles
@greggowaffles 3 жыл бұрын
Try cell(1,37).text instead. As long as both column and cell you reference have the same date format, it will work
@liza-mariwright379
@liza-mariwright379 3 жыл бұрын
@@greggowaffles No that also didn't work, it filters out all the rows. It doesn't pick up the date that I provide. Thanks anyway, I will play around a bit, I'm sure I can figure it out. ☺
@liza-mariwright379
@liza-mariwright379 3 жыл бұрын
@@greggowaffles Just wanted to let you know that I managed to get it done with ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=10, Criteria1:=1 _ , Operator:=11, Criteria2:=0, SubField:=0
@gerardvaneggermond2067
@gerardvaneggermond2067 Жыл бұрын
Hello sir, maybe you can help me, I made a code but it is too long now I want to reduce it, is this possible? One section has the following code; Application.ScreenUpdating = False If Sheets("Menu").Range("E2") = 1 Then Sheets("toplay1").Select Range("A1").Select5 ActiveCell.Formula2R1C1 = _ "=FILTER('S1'!R[1]C[1]:R[20]C[1],'S1'!R[1]C[1]:R[20]C[1]" "")" Range("B1").Select ActiveCell.Formula2R1C1 = _ "=FILTER('S1'!R[1]C[5]:R[20]C[5],'S1'!R[1]C[5]:R[20]C[5]" "")" This continues, at (c[ ]) each time 4 is added until 37 is reached Could you help me? Thanks in advance.
@eduardovallejocanales4714
@eduardovallejocanales4714 3 жыл бұрын
What about just the background color?
@greggowaffles
@greggowaffles 3 жыл бұрын
yeah, check out this video: kzbin.info/www/bejne/b3bcgXx7rbx7brM
@jameskabah2315
@jameskabah2315 4 жыл бұрын
How to lock cells and used filter in excel vba
@greggowaffles
@greggowaffles 4 жыл бұрын
you can lock the cells one time manually, and just have your code unlock the cells each time it runs and relock the cells when it ends. apologies for the late reply
@ZubairChoudhary
@ZubairChoudhary 4 жыл бұрын
Great
@greggowaffles
@greggowaffles 4 жыл бұрын
Thanks!
@llIIllIlIIllX_XIillIIllIIllIll
@llIIllIlIIllX_XIillIIllIIllIll 2 жыл бұрын
this only works with cells that has characters , it doesn't work with numbers , why???
@Denis-c9j
@Denis-c9j Жыл бұрын
hello, did you understood why does it works like that? i have the same trouble and would be so thankful if u can help me..
@llIIllIlIIllX_XIillIIllIIllIll
@llIIllIlIIllX_XIillIIllIIllIll Жыл бұрын
@@Denis-c9j hi what worked for me was changeing the formate of the whole column to "String"
@RenewYourPower
@RenewYourPower 4 жыл бұрын
What if the autofilter doesn't meet with the criteria or field?
@greggowaffles
@greggowaffles 4 жыл бұрын
that data wont get filtered. if you get an error, you can use On Error Resume Next to prevent the code from bugging out
@icezen87
@icezen87 3 жыл бұрын
how to make it dynamic? - when filtering numbers
@greggowaffles
@greggowaffles 3 жыл бұрын
Do you have an example?
@melchorfigueroa1416
@melchorfigueroa1416 5 жыл бұрын
How would you filter for all values in a list?
@greggowaffles
@greggowaffles 5 жыл бұрын
Hi Melchor! You can assign your list a name, then set an array called X equal to that list for example. From there, you Transpose X and then Split and Join the contents of X with commas. After that, you can autofilter X like you would any other array. I can make a video of that if you'd like?
@greggowaffles
@greggowaffles 5 жыл бұрын
Here you go! :-) kzbin.info/www/bejne/gmqlmX5secqdrpY
@janjancasao4509
@janjancasao4509 3 жыл бұрын
How about when the column has blank?
@greggowaffles
@greggowaffles 3 жыл бұрын
check this out: stackoverflow.com/questions/31519877/filtering-by-blanks-in-vba
@mmike27angel
@mmike27angel 3 жыл бұрын
Great!!! Thanks Gregg you really helped me so much, +1Suscriptor
@greggowaffles
@greggowaffles 3 жыл бұрын
Thanks! So glad to hear that!!
@currentpeace
@currentpeace 3 жыл бұрын
Hello, very nice video but I can't write "cells(2,6).value" it gives me this as a name. Could anybody help? thank you!
@greggowaffles
@greggowaffles 3 жыл бұрын
Hi! Thanks! You can try using this video: kzbin.info/www/bejne/d6qaYZd8bLRmjas
@currentpeace
@currentpeace 3 жыл бұрын
@@greggowaffles Hello, thank you for your answer, but that still not resolve my issue. Could you please be so kind and show me how to apply this to a particular cell address. Number 1 is ok, but I still receive "cells(2,6).values" as a text I tried to filter out. Thanks
@gopikoorikkattil6498
@gopikoorikkattil6498 3 жыл бұрын
How to make the serial number in order after apply filter?
@fksoftware
@fksoftware 3 жыл бұрын
You can't make any changes to the data set when the filter mode is true unless you copy the filtered data to a different sheet.
Dynamic Filter in Excel - Filter As You Type (with & without VBA)
13:00
Will A Basketball Boat Hold My Weight?
00:30
MrBeast
Рет қаралды 138 МЛН
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 36 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 12 МЛН
Excel VBA IF THEN Statement (with ELSEIF & Looping in cells)
12:10
Leila Gharani
Рет қаралды 321 М.
EASILY Make an Automated Data Entry Form in Excel
14:52
Kenji Explains
Рет қаралды 782 М.
VBA to Change Filter in Multiple Pivot Tables based on A Cell Value
10:50
Excel Destination
Рет қаралды 43 М.
VBA Tutorial 11:  Auto filter in Excel VBA
14:31
PK: An Excel Expert
Рет қаралды 114 М.
VBA Advanced Filter - The FASTEST way to Copy and Filter Data
18:33
Excel Macro Mastery
Рет қаралды 284 М.
Excel VBA Filter Range and Copy
12:34
The Excel Cave
Рет қаралды 11 М.
Unlock Excel Secrets: Magic Search Bar You NEVER Knew About!
17:59
PK: An Excel Expert
Рет қаралды 534 М.
SURPRISING Advanced Filter TRICK in Excel (You've Never Heard Of!)
5:59
Leila Gharani
Рет қаралды 1,2 МЛН
Will A Basketball Boat Hold My Weight?
00:30
MrBeast
Рет қаралды 138 МЛН