Loncat ke daftar isi utama

Bagaimana cara menghapus kolom kosong dengan header di Excel?

Jika Anda memiliki lembar kerja besar yang berisi banyak kolom, tetapi beberapa kolom hanya berisi header, dan sekarang, Anda ingin menghapus kolom kosong ini yang hanya memiliki header untuk menampilkan screenshot berikut. Apakah ini bisa diselesaikan di Excel dengan cepat dan mudah?

doc menghapus kolom kosong dengan header 1

Hapus kolom kosong dengan header dengan menggunakan kode VBA

Hapus beberapa kolom kosong dalam rentang / lembar kerja / buku kerja dengan Kutools for Excel


panah gelembung kanan biru Hapus kolom kosong dengan header dengan menggunakan kode VBA

Di Excel, tidak ada metode langsung untuk menangani pekerjaan ini kecuali menghapusnya satu per satu secara manual, tetapi, di sini, saya dapat memperkenalkan kode untuk Anda, lakukan hal berikut:

1. Tahan ALT + F11 kunci, lalu membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Klik Menyisipkan > Modul, dan tempel kode berikut di Modul Jendela.

Kode VBA: Hapus kolom kosong dengan header:

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. Lalu tekan F5 kunci untuk menjalankan kode ini, dan kotak prompt akan muncul untuk mengingatkan Anda bahwa kolom kosong dengan header akan dihapus, lihat tangkapan layar:

doc menghapus kolom kosong dengan header 2

4. Dan kemudian klik OK tombol, semua kolom kosong dengan hanya header di lembar kerja saat ini dihapus sekaligus.

Note: Jika ada kolom kosong, maka akan dihapus juga.


panah gelembung kanan biru Hapus beberapa kolom kosong dalam rentang / lembar kerja / buku kerja dengan Kutools for Excel

Terkadang, Anda hanya perlu menghapus kolom kosong, file Kutools untuk Excel'S Hapus Baris & Kolom Tersembunyi (Terlihat) utilitas dapat membantu Anda menyelesaikan tugas ini dengan mudah.

Kutools untuk Excel : dengan lebih dari 300 add-in Excel yang praktis, gratis untuk dicoba tanpa batasan dalam 30 hari. 

Setelah menginstal Kutools untuk Excel, lakukan hal berikut:

1. Pilih rentang kolom yang menyertakan kolom kosong yang perlu dihapus.

2. Lalu klik Kutools > Delete > Hapus Baris & Kolom Tersembunyi (Terlihat), lihat tangkapan layar:

3. di Hapus Baris & Kolom Tersembunyi (Terlihat) kotak dialog, Anda dapat memilih ruang lingkup hapus dari Lihat di drop-down yang Anda butuhkan, pilih Kolom dari Hapus jenis bagian, lalu pilih Kolom kosong dari Jenis detail bagian, lihat tangkapan layar:

doc menghapus kolom kosong dengan header 4

4. Lalu klik Ok tombol, dan hanya kolom kosong yang dihapus sekaligus. Lihat tangkapan layar:

doc menghapus kolom kosong dengan header 5

Tips: Dengan fitur canggih ini, Anda juga dapat menghapus baris kosong, kolom atau baris yang terlihat, kolom atau baris tersembunyi sesuai kebutuhan.

Klik Unduh Gratis Kutools untuk Excel Sekarang!

Alat Produktivitas Kantor Terbaik

🤖 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
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