Loncat ke daftar isi utama

Bagaimana cara menghapus sel daftar drop-down setelah memilih diubah di Excel?

Untuk daftar drop-down dependen, ketika nilai dari daftar drop-down induk diubah, nilai yang dipilih pada yang kedua akan menjadi tidak valid. Anda harus secara manual menghapus nilai yang tidak valid dari daftar drop-down kedua setelah memilih diubah di yang pertama. Pada artikel ini, saya akan menunjukkan kepada Anda metode untuk secara otomatis menghapus sel daftar drop-down dependen setelah memilih diubah di Excel.

Hapus sel daftar drop-down bergantung setelah memilih diubah dengan kode VBA


Hapus sel daftar drop-down bergantung setelah memilih diubah dengan kode VBA

Kode VBA berikut membantu Anda menghapus daftar drop-down dependen setelah memilih diubah di Excel.

1. Klik kanan tab sheet berisi daftar drop-down dependen yang akan Anda hapus secara otomatis, lalu pilih Lihat kode dari menu konteks

2. Dalam pembukaan Microsoft Visual Basic untuk Aplikasi jendela, salin di bawah kode VBA ke jendela.

Kode VBA: sel daftar drop-down tergantung kosong setelah memilih diubah

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 2018/06/04
    Application.EnableEvents = False
    If Target.Column = 5 And Target.Validation.Type = 3 Then
        Target.Offset(0, 1).Value = ""
    End If
    Application.EnableEvents = True
End Sub

Note: Dalam kode, nomor 5 adalah nomor kolom yang berisi daftar drop-down orang tua. Dalam hal ini, daftar tarik-turun orang tua saya terletak di kolom E.

3. tekan lain + Q kunci untuk menutup Microsoft Visual Basic untuk Aplikasi jendela.

Mulai sekarang, ketika perubahan dilakukan pada daftar drop-down induk, konten dari daftar drop-down kedua akan dihapus secara otomatis. Lihat tangkapan layar:


Artikel terkait:

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 (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Deleting Multiple rows gives error. Any suggestions ?
This comment was minimized by the moderator on the site
I was getting errors with multiple row deletion as well as rows being deleted that shouldn't have been cleared. Below is the solution that worked for me.

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by D 2022/08/23
On Error Resume Next
Application.EnableEvents = False
If Target.Column = 9 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 4).Value = ""
End If
End If

Application.EnableEvents = False
If Target.Column = 9 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 5).Value = ""
End If
End If

Application.EnableEvents = False
If Target.Column = 13 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).Value = ""
End If
End If

exitHandler:
Application.EnableEvents = True
Exit Sub

End Sub
This comment was minimized by the moderator on the site
I am trying to have this apply to two dependent drop downs and cannot seem to get the code right. I tried copying the code and updating the offset and using the and function and get an error each time. Any advice? I want the two columns next to the drop down to clear if it is changed instead of just one.
This comment was minimized by the moderator on the site
Hi, this is how I got it working for multiple drop downs, the "And" function didn't work for me either but this seems to. Essentially you need a different "If" statement for each drop down you want to go blank when you change the chosen value in the first drop down menu. There may be a more efficient way to do this but this worked for me!


Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 2018/06/04
Application.EnableEvents = False
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 1).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 2).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 3).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 4).Value = ""
End If
Application.EnableEvents = True
End Sub
This comment was minimized by the moderator on the site
It does not work.
This comment was minimized by the moderator on the site
Hi Marlborek,
Which Excel version are you using?
This comment was minimized by the moderator on the site
Working Perfectly
This comment was minimized by the moderator on the site
To post as a guest, your comment is unpublished.
This comment was minimized by the moderator on the site
سلام وقت شما بخیر
ما فایل اکسلی داریم که خروجیش از طریق نرم افزار همکاران سیستم هست یعنی فایل اکسل ما آنلاین به data base نرم افزار همکاران متصله(این مهم نیست برای اطلاع عرض کردم) توی این فایل فیلترهایی وجود داره که هر فیلتر یک لیست کشویی داره مشکل ما اینه که وقتی میخواهیم هر کدوم از فیلتر ها یکی از موارد لیست کشویی رو انتخاب کنیم با انتخاب لیست،لیست کشویی زود می پره یعنی بسته میشه زود و نمیشه چیزی رو انتخاب کرد،اینم بگم خدمتتون که آفیس رو حذف و نصب هم کردم بازم جواب نداد یعنی یه مدت خیلی کوتاهی جواب میده بعد به حالت قبل بر میگرده با پشتیبانی همکاران هم تماس گرفتیم گفتن مشکل از آفیستونه
(آفیسمون 2016 هست)یعنی عملا اونها هم نتونستن مشکل رو پیدا کنن.
لطفا اگه راهی هست ممنون میشم راهنماییم کنید.
با تشکر
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations