Note: The other languages of the website are Google-translated. Back to English
English English

Bagaimana cara menyembunyikan atau menampilkan baris atau kolom tertentu saat mengklik dua kali sel di Excel?

Biasanya, baris dan kolom dapat disembunyikan atau ditampilkan dengan mengklik kanan dan memilih opsi Hide atau Unhide dari menu konteks. Dalam artikel ini, kita berbicara tentang menyembunyikan atau menampilkan baris atau kolom tertentu dengan cepat dengan mengklik dua kali sel di Excel.

Sembunyikan atau tampilkan baris atau kolom tertentu saat mengklik dua kali sel dengan kode VBA

Tab Office Mengaktifkan Pengeditan dan Penjelajahan Tab di Office, dan Jadikan Pekerjaan Anda Lebih Mudah ...
Kutools for Excel Memecahkan Sebagian Besar Masalah Anda, dan Meningkatkan Produktivitas Anda hingga 80%
  • Gunakan Kembali Apa Pun: Tambahkan rumus, bagan, dan hal lain yang paling sering digunakan atau rumit ke favorit Anda, dan gunakan kembali dengan cepat di masa mendatang.
  • Lebih dari 20 fitur teks: Ekstrak Nomor dari String Teks; Ekstrak atau Hapus Bagian dari Teks; Ubah Angka dan Mata Uang ke Kata Bahasa Inggris.
  • Gabungkan Alat: Beberapa Buku Kerja dan Lembar menjadi Satu; Gabungkan Beberapa Sel / Baris / Kolom Tanpa Kehilangan Data; Gabungkan Baris dan Jumlah Duplikat.
  • Alat Pisah: Membagi Data Menjadi Beberapa Lembar Berdasarkan Nilai; Satu Buku Kerja ke Beberapa File Excel, PDF atau CSV; Satu Kolom ke Beberapa Kolom.
  • Tempel Melewati Baris Tersembunyi / Difilter; Hitung Dan Jumlah dengan Warna Latar Belakang; Kirim Email Hasil Personalisasi ke Beberapa Penerima secara Massal.
  • Filter Super: Buat skema filter tingkat lanjut dan terapkan ke setiap lembar; Jenis menurut minggu, hari, frekuensi, dan lainnya; SARING dengan tebal, rumus, komentar ...
  • Lebih dari 300 fitur canggih; Bekerja dengan Office 2007-2019 dan 365; Mendukung semua bahasa; Penerapan yang mudah di perusahaan atau organisasi Anda.

Sembunyikan atau tampilkan baris atau kolom tertentu saat mengklik dua kali sel dengan kode VBA


Kode VBA berikut dapat membantu Anda dengan cepat menyembunyikan atau memunculkan baris atau kolom tertentu dalam lembar kerja dengan mengklik ganda sel tertentu. Silakan lakukan sebagai berikut.

1. Buka lembar kerja yang ingin Anda sembunyikan baris atau kolom di dalamnya. Klik kanan tab lembar, lalu klik Lihat kode dari menu konteks

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

VBA: Sembunyikan / tampilkan baris tertentu dengan mengklik dua kali sel di lembar kerja:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20171226
    Dim xRgHidden As Range
    If (Not Intersect(Target, Range("A1:A4")) Is Nothing) And (Target.Count = 1) Then
        Set xRgHidden = Range("10:13")
        xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
    End If
End Sub

VBA: Hide/unhide specified columns by double-clicking cells in worksheet:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20171226
    Dim xRgHidden As Range
    If (Not Intersect(Target, Range("A1:A4")) Is Nothing) And (Target.Count = 1) Then
        Set xRgHidden = Range("D:E")
        xRgHidden.EntireColumn.Hidden = Not xRgHidden.EntireColumn.Hidden
    End If
End Sub

Note: In the code, A1:A4, 10:13 and D:E indicate that when double-clicking on any cell of the range A1:A4, the row 10:13 or column D:E will be hidden automatically.

3. Press the Alt + F11 keys to close the Microsoft Visual Basic for Applications window.

From now on, when double clicking any cell in range A1:A4, row 10:13 or column D:E will be hidden automatically. And double clicking the cell again to display all hidden rows or columns immediately.


Related Articles:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is very cool and extremely helpful. However, I want to repeat the same code for different sets of rows to hide when clicking on different cells. How can I use the same code multiple times in one sheet so that the code name is not the same? Thank you!
This comment was minimized by the moderator on the site
Hi,If you want to hide different sets of rows when clicking on different cells, please try to modify the cells and row numbers in below code.The below code can achieve: when double clicking A1, the row "10:13" will be hidden; when double clicking A2, the row "15:20" will be hidden, and double clicking A3 will hide row "22:23". If you want to add more conditions, please copy the code lines from If to End If and modify the cells and row numbers as you need.<div data-tag="code">Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20210409
Dim xRgHidden As Range
If (Not Intersect(Target, Range("A1")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("10:13")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
If (Not Intersect(Target, Range("A2")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("15:20")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
If (Not Intersect(Target, Range("A3")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("22:23")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
End Sub
This comment was minimized by the moderator on the site
This is so helpful! I'm wondering if their is anyway to be able to add additional 'hidden' rows over time without having to shift all the numbers in the code to make everything line up properly? Thanks so much!
This comment was minimized by the moderator on the site
This helped a lot but i'm trying to do this but everything starts hidden and hide and unhide isolated cells rather than a range? thanks!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations