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

Hoe gespecificeerde rijen of kolommen te verbergen of zichtbaar te maken bij het dubbelklikken op een cel in Excel?

Normaal gesproken kunnen rijen en kolommen worden verborgen of weergegeven door met de rechtermuisknop te klikken en de optie Verbergen of zichtbaar maken in het contextmenu te selecteren. In dit artikel hebben we het over het snel verbergen of weergeven van bepaalde rijen of kolommen door te dubbelklikken op een cel in Excel.

Verberg of maak opgegeven rijen of kolommen zichtbaar wanneer u dubbelklikt op een cel met VBA-code

Tabblad Office Bewerking en browsen met tabbladen in Office inschakelen en uw werk veel gemakkelijker maken ...
Kutools voor Excel lost de meeste van uw problemen op en verhoogt uw productiviteit met 80%
  • Hergebruik alles: Voeg de meest gebruikte of complexe formules, grafieken en al het andere toe aan uw favorieten en gebruik ze in de toekomst snel opnieuw.
  • Meer dan 20 tekstfuncties: Nummer uit tekststring halen; Extract of verwijder een deel van teksten; Converteer cijfers en valuta's naar Engelse woorden.
  • Tools samenvoegen: Meerdere werkmappen en bladen in één; Meerdere cellen / rijen / kolommen samenvoegen zonder gegevens te verliezen; Voeg dubbele rijen en som samen.
  • Hulpmiddelen splitsen: Gegevens splitsen in meerdere bladen op basis van waarde; Eén werkmap naar meerdere Excel-, PDF- of CSV-bestanden; Eén kolom naar meerdere kolommen.
  • Plakken overslaan Verborgen / gefilterde rijen; Tel en som op achtergrondkleur; Stuur gepersonaliseerde e-mails in bulk naar meerdere ontvangers.
  • Superfilter: Maak geavanceerde filterschema's en pas deze toe op elk blad Sorteer per week, dag, frequentie en meer; Filteren door vetgedrukt, formules, commentaar ...
  • Meer dan 300 krachtige functies; Werkt met Office 2007-2021 en 365; Ondersteunt alle talen; Eenvoudig te implementeren in uw onderneming of organisatie.

Verberg of maak opgegeven rijen of kolommen zichtbaar wanneer u dubbelklikt op een cel met VBA-code

Met de volgende VBA-codes kunt u snel bepaalde rijen of kolommen in een werkblad verbergen of zichtbaar maken door op een bepaalde cel te dubbelklikken. Ga als volgt te werk.

1. Open het werkblad waarin u rijen of kolommen wilt verbergen. Klik met de rechtermuisknop op de bladtab en klik vervolgens op Bekijk code vanuit het contextmenu.

2. In de opening Microsoft Visual Basic voor toepassingen -venster, kopieer de volgende VBA-code naar het codevenster.

VBA: gespecificeerde rijen verbergen / zichtbaar maken door te dubbelklikken op cellen in het werkblad:

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-2021 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

Follow Us

Copyright © 2009 - www.extendoffice.com. | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL