انتقل إلى المحتوى الرئيسي

كيفية التصفية التلقائية للصفوف بناءً على قيمة الخلية في Excel؟

عادة ، يمكن أن تساعدنا وظيفة التصفية في Excel على تصفية أي بيانات حسب حاجتنا ، لكن في بعض الأحيان ، أود تصفية الخلايا تلقائيًا بناءً على إدخال خلية يدويًا مما يعني أنه عندما أدخل معيارًا في خلية ، يمكن أن تكون البيانات تصفيتها تلقائيا مرة واحدة. هل هناك أي أفكار جيدة للتعامل مع هذه الوظيفة في Excel؟

صفوف التصفية التلقائية بناءً على قيمة الخلية التي أدخلتها برمز VBA

تصفية البيانات حسب معايير متعددة أو شرط آخر محدد ، على سبيل المثال حسب طول النص ، حسب حالة الأحرف


صفوف التصفية التلقائية بناءً على قيمة الخلية التي أدخلتها برمز VBA

لنفترض أن لدي النطاق التالي من البيانات ، الآن ، عندما أدخل المعايير في الخلية E1 و E2 ، أريد أن تتم تصفية البيانات تلقائيًا كما هو موضح أدناه:

مرشح تلقائي doc 1

1. انتقل إلى ورقة العمل التي تريد تصفية التاريخ تلقائيًا بناءً على قيمة الخلية التي أدخلتها.

2. انقر بزر الماوس الأيمن فوق علامة تبويب الورقة ، وحدد عرض الرمز من قائمة السياق ، في النافذة المنبثقة ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، يرجى نسخ ولصق الكود التالي في الفراغ وحدة نافذة ، انظر لقطة الشاشة:

كود فبا: تصفية البيانات تلقائيًا وفقًا لقيمة الخلية التي تم إدخالها:

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

مرشح تلقائي doc 2

ملاحظات: في الكود أعلاه ، A1: C20 هو نطاق بياناتك الذي تريد تصفيته ، E2 هي القيمة المستهدفة التي تريد التصفية بناءً عليها ، و E1: E2 هل ستتم تصفية خلية المعايير الخاصة بك بناءً على. يمكنك تغييرها حسب حاجتك.

3. الآن ، عند إدخال المعايير في الخلية E1 و E2 والصحافة أدخل المفتاح ، ستتم تصفية بياناتك حسب قيم الخلية تلقائيًا.


تصفية البيانات حسب معايير متعددة أو شرط آخر محدد ، على سبيل المثال حسب طول النص ، حسب حالة الأحرف

تصفية البيانات حسب معايير متعددة أو شرط محدد آخر ، على سبيل المثال حسب طول النص ، حسب حساسية حالة الأحرف ، إلخ.

كوتولس ل إكسيلالصورة سوبر تصفية الميزة هي أداة مساعدة قوية ، يمكنك تطبيق هذه الميزة لإنهاء العمليات التالية:

  • تصفية البيانات بمعايير متعددة ؛ تصفية البيانات حسب طول النص ؛
  • تصفية البيانات حسب الأحرف الكبيرة / الصغيرة ؛ تاريخ التصفية حسب السنة / الشهر / اليوم / الأسبوع / الربع

كوتولس ل إكسيل: مع أكثر من 300 وظيفة إضافية مفيدة في Excel ، يمكنك تجربتها مجانًا دون قيود خلال 30 يومًا. تنزيل وتجربة مجانية الآن!


العرض التوضيحي: صفوف التصفية التلقائية بناءً على قيمة الخلية التي أدخلتها برمز VBA

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 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