Note: The other languages of the website are Google-translated. Back to English
Masuk  \/ 
x
or
x
Daftar  \/ 
x

or

Bagaimana cara menggunakan kotak centang untuk menyembunyikan / menampilkan baris atau kolom di Excel?

Misalkan Anda perlu menggunakan kotak centang untuk menyembunyikan atau menampilkan baris atau kolom tertentu. Misalnya, ketika kotak centang Kontrol X Aktif dicentang, baris atau kolom tertentu ditampilkan, jika tidak, mereka akan disembunyikan. Artikel ini menunjukkan kepada Anda metode cara menggunakan kotak centang untuk menyembunyikan / menampilkan baris atau kolom di Excel dengan detail.

Gunakan kotak centang untuk menyembunyikan / menampilkan baris atau kolom dengan kode VBA


Gunakan kotak centang untuk menyembunyikan / menampilkan baris atau kolom dengan kode VBA

Kode VBA berikut dapat membantu Anda menyembunyikan / menampilkan baris atau kolom tertentu dengan kotak centang.

1. Setelah memasukkan kotak centang Kontrol X Aktif ke lembar kerja, klik kanan pada kotak centang lalu pilih Lihat kode dari menu klik kanan. Lihat tangkapan layar:

2. Dalam Microsoft Visual Basic untuk Aplikasi jendela, salin dan tempel kode VBA berikut ke jendela Kode.

Kode VBA: Gunakan kotak centang untuk menyembunyikan / menampilkan baris atau kolom

Private Sub CheckBox1_Click()
    [C:D].EntireColumn.Hidden = Not CheckBox1
End Sub

Catatan:

1. Dalam kode VBA, [CD]. Seluruh kolom artinya kolom C dan D akan disembunyikan atau ditampilkan dengan mencentang atau menghapus centang pada kotak yang sesuai.

2. Untuk menyembunyikan atau menampilkan baris tertentu seperti baris 6: 9, harap ubah [CD]. Seluruh kolom untuk [6: 9]. Seluruh baris dalam kode VBA.

3. tekan lain + Q tombol secara bersamaan untuk menutup Microsoft Visual Basic untuk Aplikasi jendela.

4. Sekarang matikan Mode Desain bawah Pembangun tab seperti gambar di bawah ini yang ditampilkan:

Mulai sekarang, saat kotak centang dicentang, baris atau kolom yang ditentukan akan ditampilkan. Jika tidak dicentang, baris atau kolom tertentu disembunyikan.


Artikel terkait:


Alat Produktivitas Kantor Terbaik

Kutools for Excel Memecahkan Sebagian Besar Masalah Anda, dan Meningkatkan Produktivitas Anda hingga 80%

  • Reuse: Masukkan dengan cepat rumus, bagan yang kompleks dan apa pun yang pernah Anda gunakan sebelumnya; Enkripsi Sel dengan kata sandi; Buat Milis dan mengirim email ...
  • Super Formula Bar (dengan mudah mengedit beberapa baris teks dan rumus); Membaca Tata Letak (membaca dan mengedit sel dalam jumlah besar dengan mudah); Tempel ke Rentang yang Difilter...
  • Gabungkan Sel / Baris / Kolom tanpa kehilangan Data; Pisahkan Konten Sel; Gabungkan Baris / Kolom Duplikat... Mencegah Sel Duplikat; Bandingkan Rentang...
  • Pilih Duplikat atau Unik Baris; Pilih Baris Kosong (semua sel kosong); Temukan Super dan Temukan Fuzzy di Banyak Buku Kerja; Pilih Acak ...
  • Salinan Tepat Beberapa Sel tanpa mengubah referensi rumus; Buat Referensi Otomatis ke Beberapa Lembar; Sisipkan Poin, Kotak Centang, dan lainnya ...
  • Ekstrak Teks, Tambahkan Teks, Hapus berdasarkan Posisi, Hapus Space; Membuat dan Mencetak Subtotal Paging; Konversi Konten Antar Sel dan Komentar...
  • Filter Super (simpan dan terapkan skema filter ke sheet lain); Penyortiran Lanjutan menurut bulan / minggu / hari, frekuensi dan lainnya; Filter Khusus dengan huruf tebal, miring ...
  • Gabungkan Workbooks dan WorkSheets; Gabungkan Tabel berdasarkan kolom kunci; Pisahkan Data menjadi Beberapa Lembar; Konversi Batch xls, xlsx dan PDF...
  • Lebih dari 300 fitur canggih. Mendukung Office / Excel 2007-2019 dan 365. Mendukung semua bahasa. Penerapan yang mudah di perusahaan atau organisasi Anda. Fitur lengkap uji coba gratis 30 hari. Jaminan uang kembali 60 hari.
tab kte 201905

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!
officetab bawah
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    etb1025 · 5 months ago
    What if i wanted to use 3 different checkboxes and wanted them to each toggle hiding different groups of rows? I have tried and looked all over. When I try to modify this code the checkboxes seem to interfere with each other.
  • To post as a guest, your comment is unpublished.
    Eric · 5 months ago
    What if i wanted to use 3 different checkboxes and wanted them to each toggle hiding different groups of rows? I have tried and looked all over. When I try to modify this code the checkboxes seem to interfere with each other.

  • To post as a guest, your comment is unpublished.
    Maggie · 1 years ago
    Very useful, but how can I use it to hide just a part of the spreadsheet? I mean for example cells B2:B11, how to combine those two functions? Thanks.
  • To post as a guest, your comment is unpublished.
    angela · 1 years ago
    It worked, but then when I saved the file, and reopen it doesn't work. I tried saving it as a Macro excel sheet and as a regular workbook. What have I done wrong? I want to give it to someone else to use and don't want them to be confused.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi angela,
      After adding the code into workbook, please click File > Save as, choose where to save the file, in the Save As dialog box, choose Excel Macro-Enabled Workbook (*.xlsm) from the Save as type drop-down, and finally click Save. Then send this Excel Macro-Enabled workbook to others.
  • To post as a guest, your comment is unpublished.
    May · 1 years ago
    I was try to unhide the first three role but it was not work.How can I do it ,I know it the person who send me that file wanna know my skill I can solve it or not.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi May,
      Sorry I didn't get your point.
  • To post as a guest, your comment is unpublished.
    Therese · 2 years ago
    Hello,

    Is there a way to hide only one row. If I put 6:9 all rows are hidden, but if I only put 6, it comes out as error. Would appreciate your help, thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      Please change the second line in the code to:
      [6:6].EntireRow.Hidden = Not CheckBox1.
      Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Lou · 2 years ago
    Hi,

    Hi, I've done the code, it's work good but when I try to make the same in more than one checkbox at the same sheet they work 'together', only hide or unhide the rows if all three checkboxes are selected.
    I am tryint to make these three checkboxes works independent one from another. And let the users mark only one box for at time.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Lou,
      Please make sure the checkboxes you created are ActiveX Controls checkboxes. These checkboxes works independently in your worksheet.
      Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Ed · 2 years ago
    Hello,

    I am trying to use this code to hide/unhide on a separate sheet from the checkbox. What do I have to add to make this work? Thanks in advance.

    Private Sub CheckBox1_Click()
    [C:D].EntireColumn.Hidden = Not CheckBox1
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good day,
      As the following code shown, please replace the "Sheet4" with your separate sheet name.

      Private Sub CheckBox1_Click()
      [Sheet4!C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
  • To post as a guest, your comment is unpublished.
    Cole · 3 years ago
    It seems like this code will only go one direction, i.e. only hide and not unhide them when clicked. Is there a way to correct this?
    • To post as a guest, your comment is unpublished.
      Kentthegreet · 3 years ago
      We have same problem but find a way to make it work. Please use ActiveX Controls checkbox and not at the Form Control checkbox. The code perfectly works with ActiveX checkbox.


      Private Sub CheckBox1_Click()
      [C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
    • To post as a guest, your comment is unpublished.
      Kentthegreet · 3 years ago
      We have same problem but I found out we're using Form Controls and not ActiveX Controls. The code perfectly works in ActiveX Control Checkbox button. Just turn off the Design Mode so you can click check the Checkbox.
  • To post as a guest, your comment is unpublished.
    Pieter Ramaut · 3 years ago
    @Wayne:

    Private Sub CheckBox1_Click()
    ActiveSheet.Unprotect Password:="xxxxx"
    Rows("284:351").EntireRow.Hidden = Not CheckBox1
    ActiveSheet.Protect Password:="xxxx"
    End Sub
  • To post as a guest, your comment is unpublished.
    Wayne Bailey · 4 years ago
    Is there a way to use the "Use checkbox to hide/unhide rows or columns with VBA code" on a protected worksheet?