ไปยังเนื้อหาหลัก

 วิธีอัปเดตผลลัพธ์ตัวกรองขั้นสูงโดยอัตโนมัติใน Excel

เมื่อเราใช้คุณสมบัติตัวกรองขั้นสูงเราจะพบว่าผลการกรองจะไม่เปลี่ยนแปลงโดยอัตโนมัติเมื่อมีการเปลี่ยนแปลงเกณฑ์ สิ่งนี้ต้องการให้เราใช้ฟังก์ชันตัวกรองขั้นสูงอีกครั้งเพื่อให้ได้ผลลัพธ์ใหม่ แต่คุณมีเคล็ดลับที่ดีและรวดเร็วในการอัปเดตผลลัพธ์ตัวกรองขั้นสูงโดยอัตโนมัติตามภาพหน้าจอต่อไปนี้ที่แสดงใน Excel หรือไม่?

อัปเดตผลการกรองขั้นสูงโดยอัตโนมัติด้วยรหัส VBA


อัปเดตผลการกรองขั้นสูงโดยอัตโนมัติด้วยรหัส VBA

รหัส VBA ต่อไปนี้อาจช่วยให้คุณอัปเดตผลการกรองขั้นสูงโดยอัตโนมัติเมื่อคุณเปลี่ยนเกณฑ์ตามที่คุณต้องการโปรดดำเนินการดังนี้:

1. คลิกขวาที่แท็บแผ่นงานที่คุณต้องการกรองข้อมูลโดยอัตโนมัติจากนั้นเลือก ดูรหัส จากเมนูบริบทในเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคัดลอกและวางรหัสต่อไปนี้ลงในโมดูลเปล่า:

รหัส VBA: อัปเดตผลการกรองขั้นสูงโดยอัตโนมัติ:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A5:D21").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("A1:C3"), Unique:=False
End Sub

หมายเหตุ: ในโค้ดด้านบน: A5: D21 คือช่วงข้อมูลที่คุณต้องการกรอง A1: C3 คือช่วงเกณฑ์ที่จะกรองตาม

2. จากนั้นบันทึกและปิดหน้าต่างรหัสตอนนี้เมื่อคุณเปลี่ยนเกณฑ์ในช่วงเกณฑ์ผลลัพธ์ที่กรองจะได้รับการอัปเดตโดยอัตโนมัติในครั้งเดียว

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is likely not relevant anymore. Office excel now has a FILTER function that auto updates from what I gather, making advanced filter a sort of weak pivot table. FILTER function is what should be used moving forward? Sounds like excel's solution to the issue you state above not requring VBA to do.
This comment was minimized by the moderator on the site
Hi, I am applying advanced filter for a single column for unique values(with no criteria) . I need it to be updated by itself.

Could you please help me with that?
This comment was minimized by the moderator on the site
Is there a way to do this without using VBA?
This comment was minimized by the moderator on the site
Hello, this code works perfectly, there is just one problem, the copy/paste fonction doesn't work anymore.
How could it be fixed?
Thanks in advance
This comment was minimized by the moderator on the site
@Hannah: Yes, it is possible.
In the following code the criteria is on the sheet "Filter".


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A5:D23").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Filter").Range("A1:C3"), Unique:=False
End Sub
This comment was minimized by the moderator on the site
Ce code donne une erreur 1004 référence non valide. pouvez vous corriger le code proposé?
This comment was minimized by the moderator on the site
Bonjour, merci pour votre post qui m'aide énormément. Toutefois quel serait le code à ajouter pour coller le résultat dans un tableau d'une autre feuille de fichier et si possible pour au passage ne coller que certaines colonnes ?
Pour être plus précise, en utilisant votre exemple je voudrais copier uniquement les colonnes "Product" et "Name" du résultat du filtre et ce dans une nouvelle feuille. Merci.
This comment was minimized by the moderator on the site
Can I make the criteria come from a second sheet?
This comment was minimized by the moderator on the site
it refreshes every time when any data changes.

is it possible to refresh only when criteria changes.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations