Skip i'r prif gynnwys

 Sut i gymhwyso'r un hidlydd i sawl dalen yn Excel?

Efallai y bydd yn hawdd inni gymhwyso'r swyddogaeth Hidlo i hidlo data mewn taflen waith, ond, weithiau, efallai y bydd angen i chi hidlo ar draws sawl taflen waith sydd â fformatio data cyffredin gyda'r un meini prawf hidlo. Bydd eu hidlo fesul un yn gwastraffu llawer o amser, yma, gallaf gyflwyno ffordd hawdd i'w datrys ar unwaith.

Cymhwyso'r un hidlydd i sawl taflen waith gyda chod VBA


swigen dde glas saeth Cymhwyso'r un hidlydd i sawl taflen waith gyda chod VBA

Er enghraifft, mae gen i bedair taflen waith gan fod angen hidlo'r screenshot canlynol gyda'r un meini prawf â'r Cynnyrch = KTE ar unwaith.

hidlo doc taflenni lluosog 1

Nid oes unrhyw ffordd uniongyrchol i hidlo data mewn sawl dalen yn Excel, ond, gall y cod VBA canlynol eich helpu i orffen y swydd hon, gwnewch fel a ganlyn:

1. Daliwch i lawr y ALT + F11 allweddi, yna mae'n agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Modiwlau Ffenestr.

Cod VBA: Cymhwyso'r un hidlydd i sawl taflen waith:

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. Ac yna pwyswch F5 yn allweddol i redeg y cod hwn, mae holl gynhyrchion KTE wedi'u hidlo ym mhob taflen waith ar unwaith, gweler y screenshot:

hidlo doc taflenni lluosog 2

Nodyn: O fewn y cod uchod, yn hwn xWs.Range ("A1"). AutoFilter 1, "= KTE" sgript, A1 ac = KTE yn nodi'r golofn a'r meini prawf yr ydych am eu hidlo yn seiliedig, y rhif 1 yw'r rhif colofn y gwnaethoch ei hidlo yn seiliedig arno, gallwch eu newid i'ch angen. Er enghraifft, os ydych chi am hidlo'r gorchymyn sy'n fwy na 50, does ond angen i chi addasu'r sgript hon fel hyn: xWs.Range ("B1"). AutoFilter 2, "> 50".


Hidlo data yn ôl meini prawf lluosog neu gyflwr penodol arall, megis yn ôl hyd testun, yn ôl achos sensitif, ac ati.

Kutools ar gyfer Excel'S Hidlo Super nodwedd yn ddefnyddioldeb pwerus, gallwch gymhwyso'r nodwedd hon i orffen y gweithrediadau canlynol:

  • Hidlo data gyda meini prawf lluosog; Hidlo data yn ôl hyd testun;
  • Hidlo data yn ôl llythrennau bach / llythrennau bach; Hidlo dyddiad yn ôl blwyddyn / mis / Diwrnod / wythnos / chwarter

doc-uwch-hidlo1

Kutools ar gyfer Excel: gyda mwy na 300 o ychwanegiadau Excel defnyddiol, am ddim i geisio heb unrhyw gyfyngiad mewn 30 diwrnod. Dadlwythwch a threial am ddim Nawr!

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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