Skip i'r prif gynnwys

Sut i ddileu colofnau gwag gyda phennawd yn Excel?

Os oes gennych daflen waith fawr sy'n cynnwys nifer o golofnau, ond dim ond pennawd yw rhai o'r colofnau, ac yn awr, rydych chi am ddileu'r colofnau gwag hyn sydd â phennawd yn unig i ddangos y screenshot canlynol. A ellir datrys hyn yn Excel yn gyflym ac yn hawdd?

dileu colofnau gwag gyda phennawd 1

Dileu colofnau gwag gyda phennawd trwy ddefnyddio cod VBA

Dileu colofnau gwag lluosog mewn ystod / taflen waith / llyfr gwaith gyda Kutools ar gyfer Excel


swigen dde glas saeth Dileu colofnau gwag gyda phennawd trwy ddefnyddio cod VBA

Yn Excel, nid oes dull uniongyrchol i ddelio â'r swydd hon ac eithrio eu dileu fesul un â llaw, ond, yma, gallaf gyflwyno cod i chi, gwnewch fel a ganlyn:

1. Dal 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: Dileu colofnau gwag gyda phennawd:

Sub Macro1()
'updateby Extendoffice
    Dim xEndCol As Long
    Dim I As Long
    Dim xDel As Boolean
    On Error Resume Next
    xEndCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    If xEndCol = 0 Then
        MsgBox "There is no data on """ & ActiveSheet.Name & """ .", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    Application.ScreenUpdating = False
    For I = xEndCol To 1 Step -1
        If Application.WorksheetFunction.CountA(Columns(I)) <= 1 Then
            Columns(I).Delete
            xDel = True
        End If
    Next
    If xDel Then
        MsgBox "All blank and column(s) with only a header row have now been deleted.", vbInformation, "Kutools for Excel"
    Else
        MsgBox "There are no Columns to delete as each one has more data (rows) than just a header.", vbExclamation, "Kutools for Excel"
    End If
    Application.ScreenUpdating = True
End Sub

3. Yna pwyswch F5 allwedd i redeg y cod hwn, a bydd blwch prydlon yn popio allan i'ch atgoffa y bydd y colofnau gwag gyda phennawd yn cael eu dileu, gweler y screenshot:

dileu colofnau gwag gyda phennawd 2

4. Ac yna cliciwch OK botwm, mae'r holl golofnau gwag sydd â phennawd yn unig yn y daflen waith gyfredol yn cael eu dileu ar unwaith.

Nodyn: Os oes colofnau gwag, byddant yn cael eu dileu hefyd.


swigen dde glas saeth Dileu colofnau gwag lluosog mewn ystod / taflen waith / llyfr gwaith gyda Kutools ar gyfer Excel

Weithiau, dim ond y colofnau gwag, y Kutools ar gyfer Excel'S Dileu Rhesi a Cholofnau Cudd (Gweladwy) gall cyfleustodau eich helpu i orffen y dasg hon yn rhwydd.

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

Ar ôl gosod Kutools ar gyfer Excel, gwnewch fel a ganlyn:

1. Dewiswch yr ystod colofnau sy'n cynnwys y colofnau gwag mae angen eu dileu.

2. Yna cliciwch Kutools > Dileu > Dileu Rhesi a Cholofnau Cudd (Gweladwy), gweler y screenshot:

3. Yn y Dileu Rhesi a Cholofnau Cudd (Gweladwy) blwch deialog, gallwch ddewis y cwmpas dileu o'r gwymplen Edrych i mewn yn ôl yr angen, dewiswch colofnau oddi wrth y Dileu math adran, ac yna dewis Colofnau gwag oddi wrth y Math manwl adran, gweler y screenshot:

dileu colofnau gwag gyda phennawd 4

4. Yna cliciwch Ok botwm, a dim ond y colofnau gwag sy'n cael eu dileu ar unwaith. Gweler y screenshot:

dileu colofnau gwag gyda phennawd 5

Awgrymiadau: Gyda'r nodwedd bwerus hon, gallwch hefyd ddileu rhesi gwag, colofnau gweladwy neu res, colofnau cudd neu resi yn ôl yr angen.

Cliciwch Am Ddim Lawrlwytho Kutools ar gyfer Excel 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 (10)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
All I keep getting is "There are no Columns to delete as each one has more data (rows) than just a header." Yet I know for a fact I have about 700 columns with a header and no data. I have a spreadsheet with over 900 columns and only 200ish have data below the header. Another macro worked but I had to delete the header row. So I know this macro is not working correctly. What's up?
This comment was minimized by the moderator on the site
Hello, Paul
The VBA code works well if there is only one header row in the worksheet, if there are two or more header rows, it will pop out the prompt message you said.
So you need to check out if there are hidden heading rows in your data.
Thank you!
This comment was minimized by the moderator on the site
Hello, I have the same issue, I know by fact that I have a lot of columns that have only headers but the same Error "There are no Columns to delete as each one has more data (rows) than just a header." and I have checked there are no hidden rows in the data.
Can anyone help me ?
This comment was minimized by the moderator on the site
Hi, Simoch
In this case, you can upload your Excel file attachment here, so that we can help to check the problem if you don't mind.
Thank you!
This comment was minimized by the moderator on the site
Dear skyyang no need, It worked perfecty now !! thank you so much for that VBA code !
Rated 5 out of 5
This comment was minimized by the moderator on the site
Amazing! You are correct. There must have been something hidden. Everything is working great now. Thank you so much for the quick reply.
This comment was minimized by the moderator on the site
Can this be saved in one spreadsheet and run on other files?
This comment was minimized by the moderator on the site
Works perfectly. Greatly appreciated
This comment was minimized by the moderator on the site
OMG, this is genius!!! thank you
This comment was minimized by the moderator on the site
Hi, Thanks for the nice code above. Is it free to use?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations