Skip i'r prif gynnwys

Sut i ddileu taflen waith yn seiliedig ar werth celloedd yn Excel?

Gan dybio, mae gen i sawl taflen waith o fewn llyfr gwaith, nawr, rydw i eisiau dileu'r taflenni yn seiliedig ar werth celloedd. Er enghraifft, os yw'r gell A1 benodol yn cynnwys y testun “KTE”, mae angen dileu'r holl daflenni y mae gan destun A1 y testun hwn ar unwaith. Efallai y bydd yr erthygl hon yn eich helpu i ddelio â'r dasg hon yn Excel.

Dileu taflen waith yn seiliedig ar werth celloedd gyda chod VBA


swigen dde glas saeth Dileu taflen waith yn seiliedig ar werth celloedd gyda chod VBA

Yma, byddaf yn cyflwyno cod i chi ddileu'r holl daflenni y mae gan y gell benodol werth penodol, gwnewch fel a ganlyn:

1. Dal i lawr y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

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

Cod VBA: Dileu taflen waith yn seiliedig ar werth celloedd:

Sub deletesheetbycell()
'Updateby Extendoffice
    Dim shName As String
    Dim xName As String
    Dim xWs As Worksheet
    Dim cnt As Integer
    shName = Application.InputBox("Input the text to delete the sheets based on:", "Kutools for Excel", _
                                    "", , , , , 2)
    Application.DisplayAlerts = False
    cnt = 0
    For Each xWs In ThisWorkbook.Sheets
        If xWs.Range("A1").Value = shName Then
            xWs.delete
            cnt = cnt + 1
        End If
    Next xWs
    Application.DisplayAlerts = True
    MsgBox "Have deleted" & cnt & "worksheets", vbInformation, "Kutools for Excel"
End Sub

Nodyn: Yn y cod uchod, A1 yw'r gell benodol sy'n cynnwys testun penodol rydych chi am ddileu'r taflenni yn seiliedig arno.

3. Yna, pwyswch F5 allwedd i redeg y cod hwn, ac mae blwch prydlon yn cael ei popio allan i'ch atgoffa i fewnbynnu'r gwerth penodol rydych chi am ddileu'r taflenni yn seiliedig arno, gweler y screenshot:

taflen dileu doc ​​yn ôl cell 1

4. Ac yna cliciwch OK botwm, mae'r holl daflenni y mae gan destun A1 y testun KTE wedi'u dileu ar unwaith. Gweler y screenshot:

taflen dileu doc ​​yn ôl cell 2

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 (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello again, Nevermind on my last question. I added the following before and after the Delete line:Application.DisplayAlerts = False
Application.DisplayAlerts = True

This comment was minimized by the moderator on the site
quick question, the above code works for me for deleting worksheets which contain the value which is entered, but what if i want to delete worksheets which do not contain value entered. I tried replacing the "=" operator with the <>" operator, but it does not work. Thanks!
This comment was minimized by the moderator on the site
Ankur,
As you said, you just need to change the "=" to " <>" as below code:

Sub deletesheetbycell()
Dim shName As String
Dim xName As String
Dim xWs As Worksheet
Dim cnt As Integer
shName = Application.InputBox("Input the text not delete the sheets based on:", "Kutools for Excel", _
"", , , , , 2)
Application.DisplayAlerts = False
cnt = 0
For Each xWs In ThisWorkbook.Sheets
If xWs.Range("A1").Value <> shName Then
xWs.Delete
cnt = cnt + 1
End If
Next xWs
Application.DisplayAlerts = True
MsgBox "Have deleted" & cnt & "worksheets", vbInformation, "Kutools for Excel"
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Good afternoon,
Could you tell me if there is a way to automatically respond yes when prompted to delete the sheet? Thank you very much.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations