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

 วิธีใช้ตัวกรองเดียวกันกับแผ่นงานหลายแผ่นใน Excel

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

ใช้ตัวกรองเดียวกันกับแผ่นงานหลายแผ่นด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา ใช้ตัวกรองเดียวกันกับแผ่นงานหลายแผ่นด้วยรหัส VBA

ตัวอย่างเช่นฉันมีสี่แผ่นงานเนื่องจากภาพหน้าจอต่อไปนี้จะต้องถูกกรองด้วยเกณฑ์เดียวกับที่ Product = KTE พร้อมกัน

doc กรองหลายแผ่น 1

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

1. กด ALT + F11 จากนั้นจะเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ โมดูล หน้าต่าง.

รหัส VBA: ใช้ตัวกรองเดียวกันกับแผ่นงานหลายแผ่น:

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("A1").AutoFilter 1, "=KTE"
    Next
End Sub

3. จากนั้นกด F5 กุญแจสำคัญในการเรียกใช้รหัสนี้ผลิตภัณฑ์ทั้งหมดของ KTE ได้รับการกรองในแผ่นงานทั้งหมดพร้อมกันดูภาพหน้าจอ:

doc กรองหลายแผ่น 2

หมายเหตุ: ภายในโค้ดข้างต้นในนี้ xWs.Range ("A1") ตัวกรองอัตโนมัติ 1, "= KTE" สคริปต์ A1 และ = KTE ระบุคอลัมน์และเกณฑ์ที่คุณต้องการกรองตามหมายเลข 1 คือหมายเลขคอลัมน์ที่คุณกรองตามคุณสามารถเปลี่ยนได้ตามความต้องการของคุณ ตัวอย่างเช่นหากคุณต้องการกรองลำดับที่มากกว่า 50 คุณก็ต้องแก้ไขสคริปต์นี้ดังนี้: xWs.Range ("B1") ตัวกรองอัตโนมัติ 2, "> 50".


กรองข้อมูลตามเกณฑ์หลายข้อหรือเงื่อนไขเฉพาะอื่น ๆ เช่นตามความยาวของข้อความโดยคำนึงถึงขนาดตัวพิมพ์เป็นต้น

Kutools สำหรับ Excel's ซุปเปอร์ฟิลเตอร์ คุณลักษณะเป็นยูทิลิตี้ที่มีประสิทธิภาพคุณสามารถใช้คุณสมบัตินี้เพื่อสิ้นสุดการดำเนินการต่อไปนี้:

  • กรองข้อมูลด้วยหลายเกณฑ์ กรองข้อมูลตามความยาวข้อความ
  • กรองข้อมูลตามตัวพิมพ์ใหญ่ / เล็ก กรองวันที่ตามปี / เดือน / วัน / สัปดาห์ / ไตรมาส

doc-super-filter1

Kutools สำหรับ Excel: ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน ดาวน์โหลดและทดลองใช้ฟรีทันที!

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

🤖 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 (48)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Hello, your code works really well. What about if I want to filter more than one cell value. For example: KTE and KTO? thank you for your help
This comment was minimized by the moderator on the site
Hello, your code works really well. What about if I want to filter more than one cell value. For example: KTE and KTO
This comment was minimized by the moderator on the site
Hi,
i have a work book 20+ sheets, and have to filter each sheet in different column but the same number "0 (Zero)" as in the column "P" in the attached image. along with i have to print preview the sheets which i have mentioned. How to di it sir. Each sheet has link with another or several sheets has linked to specific sheet.
This comment was minimized by the moderator on the site
Works a treat, thank you.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Is it possible to use the code to filter where it does not contain a zero.

I have a workbook with sheets up to 20 sometimes, where one column is always the same in each sheet, want to filter out all zeros.

Hope this makes sense.
This comment was minimized by the moderator on the site
Hello, Richard,
To filter the data exclude the zeros, please apply the below vba code:
Note: in the code, in this xWs.Range("C1").AutoFilter 3, "<>0" script, C1 and <>0 indicates the column and criteria which you want to filter based on, the number 3 is the column number you filtered based on, you can change them to your need.
Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("c1").AutoFilter 3, "<>0"
    Next
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
I want to use this code to filter on a column across multiple worksheets, the column will always have numbers in it, but I want the auto filter to remove zero values, leaving just minus and plus numbers.

Is this possible?
This comment was minimized by the moderator on the site
I have a spreadsheet with 2 tabs, I want that when I filter one tab, the other respects the filtered items and is also filtered with the same values, how to do that?
This comment was minimized by the moderator on the site
Hello, Fabio,
To solve your problem, you can use the VBA code in this article, and please remeber to change the cell reference and criteria in the code.
Please try again, hope it can help you!
This comment was minimized by the moderator on the site
I am copying and pasting exactly but keep getting "Compile Error: Invalid outside procedure". I have only changed the criteria to match what I need specifically.. below:

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("D3").AutoFilter 1, "=Paige"
Next
End Sub
This comment was minimized by the moderator on the site
Hello, Paige,
I have tested your code, and it works well in my workbook.
Could you upload your excel file here, so that we can check where the problem is.
Thank you!
This comment was minimized by the moderator on the site
Amazing work! this macro is great.
This comment was minimized by the moderator on the site
Thank you skyyang Please how do i remove the hidden rows after filtering?
This comment was minimized by the moderator on the site
Hello, Akoma,
To remove all hidden rows after filtering, please apply the below code: (Note: This code will remove all hidden rows in the worksheet, and it will not undo, so you need backup your data.)
Sub DeleteHiddenRows()
Dim sht As Worksheet
Dim LastRow
Set sht = ActiveSheet
LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
For i = LastRow To 1 Step -1
If Rows(i).Hidden = True Then Rows(i).EntireRow.Delete
Next
End Sub

Please try, hope it can help you!
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