Loncat ke daftar isi utama

Bagaimana cara menghapus baris berdasarkan nilai sel di Excel?

Untuk menghapus atau menghapus beberapa baris dengan cepat berdasarkan nilai sel di Excel, Anda mungkin perlu memilih seluruh baris yang berisi nilai sel tertentu terlebih dahulu, lalu pergi untuk menghapusnya. Tampaknya tidak ada cara cepat untuk menghapus baris berdasarkan nilai sel tetapi menggunakan kode VBA. Berikut beberapa trik cepat untuk membantu Anda.


Hapus baris berdasarkan nilai sel dengan fitur Find and Replace

Di Excel, Anda bisa menerapkan fitur Temukan dan Ganti yang kuat untuk menghapus baris berdasarkan nilai sel tertentu dengan mudah. Harap lakukan sebagai berikut:

1. Pilih rentang di mana Anda akan menghapus baris berdasarkan nilai sel tertentu, dan buka kotak dialog Temukan dan Ganti dengan menekan Ctrl + F kunci secara bersamaan.

2. Di kotak dialog Temukan dan Ganti, ketikkan nilai sel tertentu (dalam kasus kami, kami memasukkan Soe) ke dalam Find what kotak, dan klik Find All tombol. Lihat screenshot pertama di bawah ini:

3. Pilih semua hasil pencarian di bagian bawah kotak dialog Temukan dan Ganti, dan tutup kotak dialog ini. (Note: Anda dapat memilih salah satu hasil pencarian, lalu Ctrl + A kunci untuk memilih semua hasil yang ditemukan. Lihat gambar kedua di atas.)
Dan kemudian Anda dapat melihat semua sel yang berisi nilai tertentu dipilih.

4. Silakan klik kanan sel yang dipilih dan pilih Delete dari menu klik kanan. Dan kemudian periksa Entire row pilihan di kotak dialog Hapus yang muncul, dan klik OK tombol. Sekarang Anda akan melihat semua sel yang berisi nilai tertentu dihapus. Lihat tangkapan layar di bawah ini:

Dan kemudian seluruh baris telah dihapus berdasarkan nilai tertentu.


Hapus baris berdasarkan nilai sel dengan kode VBA

Dengan kode VBA berikut, Anda dapat dengan cepat menghapus baris dengan nilai sel tertentu, lakukan langkah-langkah berikut:

1. Tap Alt + F11 kunci pada saat yang sama untuk membuka Microsoft Visual Basic for applications jendela,

2. Klik Insert > Module, dan masukkan kode berikut ke dalam Modul:

VBA: Hapus seluruh baris berdasarkan nilai sel

Sub DeleteRows()
'Updateby20211217
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
Dim xTitleId As String
Dim xArr
Dim xF As Integer
Dim xWSh As Worksheet
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set rng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, rng.Address, Type:=8)
If InputRng Is Nothing Then Exit Sub
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
Set xWSh = InputRng.Worksheet
For Each rng In InputRng
    If rng.Value = DeleteStr Then
        If DeleteRng Is Nothing Then
            Set DeleteRng = rng
        Else
            Set DeleteRng = Application.Union(DeleteRng, rng)
            Set DeleteRng = DeleteRng.EntireRow
        End If
    End If
Next
xArr = Split(DeleteRng.AddressLocal, ",")
DeleteRng.Select
DeleteRng.Delete
For xF = UBound(xArr) To 0 Step -1
    Set DeleteRng = xWSh.Range(xArr(xF))
    DeleteRng.Delete
Next
End Sub

3. Kemudian klik Run tombol untuk menjalankan kode.

4. Pada kotak dialog yang muncul, pilih rentang di mana Anda akan menghapus baris berdasarkan nilai tertentu, dan klik OK .

5. Di kotak dialog lain, ketikkan nilai tertentu yang akan Anda hapus berdasarkan baris, dan klik OK tombol. Lihat tangkapan layar:

Dan kemudian Anda akan melihat seluruh baris telah dihapus berdasarkan nilai yang ditentukan.


Hapus baris berdasarkan satu atau dua nilai sel dengan Kutools for Excel

Jika sudah terpasang Kutools for Excel, nya Select Specific Cells Fitur dapat membantu Anda dengan cepat menghapus baris dengan nilai tertentu. Harap lakukan sebagai berikut:

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now

1. Pilih rentang yang akan Anda hapus baris berdasarkan nilai tertentu, dan klik Kutools > Select > Select Specific Cells. Lihat tangkapan layar:

2. Pada kotak dialog Select Specified Cells pembuka, silakan centang Entire row pilihan, pilih Contains dari Specific type daftar drop-down, masukkan nilai yang ditentukan ke dalam kotak kanan, dan klik Ok tombol (Lihat tangkapan layar di atas).
Setelah menerapkan fitur ini, kotak dialog akan muncul dan menunjukkan kepada Anda berapa banyak sel yang telah ditemukan berdasarkan kriteria yang ditentukan. Silakan klik OK tombol untuk menutupnya.

3. Sekarang seluruh baris dengan nilai tertentu dipilih. Silakan klik kanan baris yang dipilih, dan klik Delete dari menu klik kanan. Lihat tangkapan layar di bawah ini:

Note: Ini Select Specific Cells Fitur mendukung untuk menghapus baris dengan satu atau dua nilai tertentu. Untuk menghapus baris berdasarkan dua nilai yang ditentukan, harap tentukan nilai lain di Specific type bagian dari kotak dialog Select Specific Cells seperti gambar berikut yang ditampilkan:

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now


Hapus baris berdasarkan beberapa nilai sel dengan Kutools for Excel

Dalam beberapa kasus, Anda mungkin perlu menghapus baris berdasarkan beberapa nilai sel dari kolom / daftar lain di Excel. Berikut akan saya perkenalkan Kutools for Excel's Select Same & Different Cells fitur untuk menyelesaikannya dengan cepat dengan mudah.

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now

1. Klik Kutools > Select > Select Same & Different Cells untuk membuka kotak dialog Select Same & Different Cells.

2. Dalam pembukaan Select Same & Different Cells kotak dialog, lakukan hal berikut (lihat tangkapan layar):

(1) Dalam Find values in kotak, pilih kolom di mana Anda akan menemukan nilai-nilai tertentu;
(2) Dalam According to kotak, pilih kolom / daftar dengan beberapa nilai yang barisnya akan Anda hapus;
(3) Dalam Based on bagian, harap periksa Each row pilihan;
(4) Dalam Find bagian, harap periksa Same Values pilihan;
(5) Periksa Select entire rows opsi di bagian bawah kotak dialog pembuka.
Note: Jika dua kolom tertentu berisi tajuk yang sama, harap periksa My data has headers .

3. klik Ok tombol untuk menerapkan utilitas ini. Dan kemudian kotak dialog keluar dan menunjukkan berapa banyak baris yang telah dipilih. Cukup klik OK tombol untuk menutupnya.

Dan kemudian semua baris yang berisi nilai di antara daftar yang ditentukan telah dipilih.

4. Klik Home > Delete > Delete Sheet Rows untuk menghapus semua baris yang dipilih.


Demo: hapus baris berdasarkan satu atau beberapa nilai sel di Excel


Kutools untuk Excel: Lebih dari 300 alat praktis di ujung jari Anda! Mulai uji coba gratis 30 hari Anda tanpa batasan fitur hari ini. Download 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 (39)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
In given range, if any cell contains defined text the entire row gets deleted.

Pls share code
This comment was minimized by the moderator on the site
Hi Yogesh,
On this webpage, the second method is to delete rows by cell values with VBA code. You can go to there and copy the code directly!
https://www.extendoffice.com/documents/excel/815-excel-remove-rows-based-on-cell-value.html#vba
This comment was minimized by the moderator on the site
There are two issues with the code posted as of this date. 1) the variable xTitleId is not declared, which causes a compilation error if Option Explicit is in use. 2) With Excel 2016, it appears that a range is limited to 129 areas. Each discontiguous matching cell found in the loop creates another area in the DeleteRng variable. Unfortunately, the Union method does not raise an error if that number of areas is exceeded; it just ignores the remaining cells. When the loop is finished, DeleteRng will have no more than 129 areas.
This comment was minimized by the moderator on the site
Hi TomTheToolman,
Thank you so much for your feedback. I've already updated the new code in the article. If you have any other questions, please don't hesitate to let me know.
Amanda
This comment was minimized by the moderator on the site
very well. Thank you!
This comment was minimized by the moderator on the site
Can someone help me...If 3rd column has value 0, then delete all values of corresponding column 1st. In this case answer should be the last line only.... Check MenuName ID 3149 VNLA MILFLLE 2 3149 TURKEY PNN 0 3149 R. BEEF PNN 0 3149 MIX MOCHA 38 3150 M.G.R 1/2 0 3150 THE PEPPE L 0 3150 MIX SLD 0 3150 EGGPLANT 0 3150 STILL WATER 7 3151 MIX MOCHA 38
This comment was minimized by the moderator on the site
Thanks for sharing. I am actually looking for a code that doesn't ask user for range but instead selects a specific column say column "A" and runs till the last row of that column. Can you please help..
This comment was minimized by the moderator on the site
Hi everybody, I am wondering what can we do to delete the following (According to the example shown in this page): Soe appears at several date (sept, October... etc). What I would like is to delete the line where Soe is but to keep the line with last date she appeared. In addition, some lines could be in double but I still want to keep it. So for example, you have the lines: - July 3 /Soe - Sep 4 / Soe - Sep 4 / Soe - Oct 19/ Soe - Nov 13 / Soe - Nov 13 / Soe and what I want to keep is: - Nov 13 / Soe - Nov 13 / Soe My real case is: I have different EAN code and version 1, 2, 3 or 4 and I want to keep the line where the version is the higher. e.g.: I have: - EAN 1 / Version 1 - EAN 1 / Version 1 - EAN 1 / Version 2 - EAN 1 / Version 2 - EAN 2 / Version 2 - EAN 2 / Version 3 - EAN 2 / Version 3 and I want to keep: - EAN 1 / Version 2 - EAN 1 / Version 2 - EAN 2 / Version 3 - EAN 2 / Version 3 I am searching since hours and I am completely blocked on this issue. Many thanks in advance for your brain and help. Best, Marion
This comment was minimized by the moderator on the site
Hi, Thank you this was really helpful. However, there's an error that pops up when I run the codes it says "Object variable or with block variable not set" and it points to " the line DeleteRNG.EntireRow.Delete". Could you please help me with debugging this. Thanks.
This comment was minimized by the moderator on the site
I am trying to use this macro in order to delete unused formulas, because excel views blank formula cells as a zero value and will print extra pages. I was hoping when I deleted the unused formulas, when I printed it would only print the pages that had information. This is not the case and I really need help to find a solution. I have tried using this formula and it is not working and prints three extra pages that I do not need even with the extra formulas being deleted. Sub selectonly() ' ' selectonly Macro ' Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)" End Sub
This comment was minimized by the moderator on the site
thank you so much. That save me a lot of time
This comment was minimized by the moderator on the site
Trying to find a delete Function that will delete entire designated rows automatically, based on certain values or certain text contained in other cell(s), using only automated formulas.
This comment was minimized by the moderator on the site
How can i delete selected cell that i want based on value that i entered for example : A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 C3 D3 A4 B4 C4 D4 When i entered in some cell for example "2" then 2 row will be deleted from A3:D4. If i entered "1" then 1 row will be deleted from A4:D4. if i entered "3" then 3 row will be deleted from A2:D4
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