메인 컨텐츠로 가기

Excel에서 셀 값을 기반으로 행을 자동 필터링하는 방법은 무엇입니까?

일반적으로 Excel의 필터 기능은 필요한 데이터를 필터링하는 데 도움이 될 수 있지만 때로는 수동 셀 입력을 기반으로 셀을 자동 필터링하고 싶습니다. 즉, 셀에 기준을 입력 할 때 데이터가 한 번에 자동으로 필터링됩니다. Excel에서이 작업을 처리 할 좋은 아이디어가 있습니까?

VBA 코드로 입력 한 셀 값을 기반으로 행 자동 필터링

여러 기준 또는 기타 특정 조건 (예 : 텍스트 길이, 대소 문자 구분)으로 데이터 필터링


VBA 코드로 입력 한 셀 값을 기반으로 행 자동 필터링

다음과 같은 데이터 범위가 있다고 가정하면 셀 E1 및 E2에 기준을 입력 할 때 아래 스크린 샷과 같이 데이터가 자동으로 필터링되기를 원합니다.

문서 자동 필터 1

1. 입력 한 셀 값을 기준으로 날짜를 자동 필터링하려는 워크 시트로 이동합니다.

2. 시트 탭을 마우스 오른쪽 버튼으로 클릭하고 코드보기 컨텍스트 메뉴에서 튀어 나온 응용 프로그램 용 Microsoft Visual Basic 창에서 다음 코드를 복사하여 빈 칸에 붙여 넣으십시오. 모듈 창, 스크린 샷 참조 :

VBA 코드 : 입력 된 셀 값에 따라 데이터 자동 필터링 :

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
   If Target.Address = Range("E2").Address Then
       Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
   End If
End Sub

문서 자동 필터 2

주의 사항: 위 코드에서 A1 : C20 필터링하려는 데이터 범위입니다. E2 필터링 기준이되는 대상 값입니다. E1 : E2 기준 셀이 기준으로 필터링됩니다. 필요에 따라 변경할 수 있습니다.

3. 이제 셀에 기준을 입력하면 E1E2 키를 누릅니다 엔터 버튼 키를 누르면 데이터가 자동으로 셀 값으로 필터링됩니다.


여러 기준 또는 기타 특정 조건 (예 : 텍스트 길이, 대소 문자 구분)으로 데이터 필터링

여러 기준 또는 기타 특정 조건 (예 : 텍스트 길이, 대소 문자 구분 등)으로 데이터를 필터링합니다.

Excel 용 Kutools슈퍼 필터 기능은 강력한 유틸리티이므로이 기능을 적용하여 다음 작업을 완료 할 수 있습니다.

  • 여러 기준으로 데이터를 필터링합니다. 텍스트 길이로 데이터 필터링;
  • 대문자 / 소문자로 데이터 필터링; 년 / 월 / 일 / 주 / 분기별로 날짜 필터링

Excel 용 Kutools: 300 개 이상의 편리한 Excel 추가 기능으로 30 일 동안 제한없이 무료로 사용해 볼 수 있습니다. 지금 다운로드 및 무료 평가판!


데모 : VBA 코드로 입력 한 셀 값을 기반으로 행 자동 필터링

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (36)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
hi

thank you - this code was a life saver

but if I wish to filter when the value on E2 contains the search text.
so if i search for Grade1
it should filter
Grade1
ExampleGrade1
Grade1ETC


many thanks in advance
This comment was minimized by the moderator on the site
I scanned through the comments and didn't see a specific answer. I am looking to filter a Table that changes based on a DB query, The table range will change every time the query is refreshed, How can we account for this in the code? The function becomes pointless if I have to direct users edit the VBA code every time they refresh the table.
This comment was minimized by the moderator on the site
Good day,

I have made sheet1 with the table in the example. In sheet2 all the data are referenced to the table in sheet1.

In sheet2 I can choose the grades exactly as in the example. That works OK.

However when I change a Grade of a student in sheet1 the list is not updated in sheet2. So the filter does not work automatic.

How can this be done?
This comment was minimized by the moderator on the site
Hello, is there a way to quickly modify the VBA code to filter on values bigger than in selected cell?
This comment was minimized by the moderator on the site
Hi there,

Thank you for the great content, however I am having some issues and was wondering whether you had any ideas why.

I have adjusted my ranges so my code reads:

Sub AutoFilter()
If Target.Address = Range("E13:F14").Address Then
Worksheets('Data Archive').Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("F10:F1048576")
End If
End Sub


However, when I run the macro a "Compile Error: Syntex Error" message appears.

Thank you in advance

Stan
This comment was minimized by the moderator on the site
Hello, Stan,
Do you set the data range and criteria range correctly in the code?Or you can take your data range as a screenshot here.
Thank you!
This comment was minimized by the moderator on the site
Thank you very much for this. It worked for me fine to a certain extent, please let me explain:

I have multiple tables in my workbook. When I applied the above code, it only worked for one table, but not for the other two tables. Let's say the first table is, as in your example, from A1:C20. The second table is from A22:C40. The third from A42:C60. All tables have the info about the "Grade", however they have different columns & Date and therefore cannot be consolidated into one big tables but rather 3 smaller tables.

How would the code need to like like so that if I put the criteria: "Grade1", all 3 tables will be automatically filtered for "Grade1" ?

Thank you very much in advance.

Best regards
This comment was minimized by the moderator on the site
Thank you, for this, it was really helpful. i just have one question, after selected the name in the drop down menu (i have names as criteria), it only shows people with that name, as it should, but how can i do so after i have selected a name, then i want so see all the rows of my table??

hope you can help me out.

kind regards
This comment was minimized by the moderator on the site
Hi, Peter,
This code is worked well for fitering the entire rows of the data, could you enter your table range correctlly?

A1:C20 is the range of your data, E1:E2 is the criteria range.
Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
This comment was minimized by the moderator on the site
Hey guys,
perfect Explanation, thank you very much.
1 Little question: if I want to filter with 2,3 4 or more criterias how do I do this?
For example I want to say I wanna see the Name Henry, with Grade 1 and this Age...so not just 1 criteria but for example 3..=?


thanks for the respond


Kind regards,


TIM
This comment was minimized by the moderator on the site
Hi, tim,
To auto filter data based on multiple criteria, you should apply the below code: (please change the cell references to your need)

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice
Dim xVStr As String
Dim xFStr As String
xVStr = "E22:G22" 'the criteria that you want to filter based on
xFStr = "E21:G22" 'the range contains the header of the criteria
If Not (Intersect(Range(xVStr), Target) Is Nothing) Then
Range("A1:C17").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=Range(xFStr)
End If
End Sub


Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hello,

What if I got the filtered data in a different tab(sheet 2) in the same workbook and the cell that the filter needs to refer to is in the first tab(sheet 1). I used this VBA but is not working like that, only if I have both the criteria cell(E2 in this VBA) in the same tab with the filtered data(A1:C20)
This comment was minimized by the moderator on the site
There might be a mistake in the instructions. Instead of pasting the code into a blank Module, one should paste it into the Sheet window. For example, if the macro is to work on Sheet1, the code should be pasted into Microsoft Excel Objects -> Sheet1(Sheet1). Only then it works for me on Excel 2016.

Thanks for the code!
This comment was minimized by the moderator on the site
Hi, mjr,
There is no mistake in this article, the article said, you should put the VBA code into the sheet module by right click the sheet name and then choose View Code to go to the module.
But, your operation is correct as well.
Thank you for your comment.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations