Vai al contenuto principale

Come nascondere automaticamente le righe se le celle vuote in una colonna?

Se disponi di un intervallo di dati che popola alcune celle vuote in una colonna e ora, desideri nascondere automaticamente le righe che contengono le celle vuote in quella colonna. Esistono buoni modi per risolvere questo lavoro in Excel in modo rapido e semplice?

Nascondi automaticamente le righe se celle vuote in una colonna con codice VBA


freccia blu freccia destra Nascondi automaticamente le righe se celle vuote in una colonna con codice VBA

Il codice seguente può aiutarti a nascondere tutte le righe se celle vuote in una colonna specifica contemporaneamente e se elimini il contenuto della cella in quella colonna, anche le righe verranno nascoste automaticamente. Si prega di fare quanto segue:

1. Fare clic con il pulsante destro del mouse sulla scheda del foglio in cui si desidera nascondere automaticamente le righe se sono presenti celle vuote in una colonna, quindi scegliere Visualizza codice dal menu contestuale, nel saltato fuori Microsoft Visual Basic, Applications Edition finestra, copia e incolla il seguente codice nello spazio vuoto Moduli:

Codice VBA: nascondi automaticamente le righe se celle vuote in una colonna:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("A1:A20")
            If xRg.Value = "" Then
                xRg.EntireRow.Hidden = True
        
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True
End Sub

doc nascondi automaticamente le righe 1

Note:: Nel codice sopra, A1: A20 è l'elenco dei dati che contiene le celle vuote che desideri nascondere automaticamente.

2. Quindi torna al foglio di lavoro e ora, quando fai doppio clic su una cella e premi entrare chiave, le righe che contengono celle vuote nella colonna A sono state nascoste in una volta e se si cancella qualsiasi contenuto di cella nelle celle specificate della colonna A, le righe verranno nascoste automaticamente.

doc nascondi automaticamente le righe 2

 

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!

 

Comments (35)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I already copied the code, but nothing happened in my worksheet, Do I need to change anything with the code?
Thank you.
This comment was minimized by the moderator on the site
I already copied the code, but nothing happened in my worksheet, Do I need to change anything with the code?
Thank you.
This comment was minimized by the moderator on the site
I'm trying to find a way hide blank rows in sheet2 from A2:A20, if Sheet!A5=Yes. any suggestion?
This comment was minimized by the moderator on the site
Hi, i'm having issues with the "automation" of the macro. I'm searching for a way for the code to work as an automated process without the needs of "manually" running the macro. i've been using my own variant of your code due to me finding issues to use your code. This is my variant:

Sub HideRows()
Dim xRg As Range
Application.ScreenUpdating = False
For Each xRg In Range("A3:A800")
If (xRg.Value = "") Then
xRg.EntireRow.Hidden = True
Else
xRg.EntireRow.Hidden = False
End If
Next xRg
Application.ScreenUpdating = True
End Sub

I'm trying to create a spreadsheet which requires everchanging values, therefore would require a genuine "automated" procress. I'm relatively new to VBA and if your code actually already meets my requirements would you mind helping/teach me to apply it in VBA? Thanks.
This comment was minimized by the moderator on the site
Hello, Vian
In fact, the code in our article can be run automatically.
You must copy and paste the code into the code module of current worksheet, then return to the worksheet, double-click any cell, and press the Enter key, the row containing the blank cell will be is directly hidden.

Please follow the method in this article step by step, hope it can help you!
Thank you!
This comment was minimized by the moderator on the site
apakah ada rumus lain?, saya berharap baris kosong itu akan terhapus saat mencetak file menjadi PDF tapi tampilan di excelnya tetap
This comment was minimized by the moderator on the site
Hello, Nurjanah
To solve your problem, first, you should hide the blank rows, and then print the data, after printing the data, you need unhide the blank rows again. Please do as this:
1. Apply this formula: =COUNTA(A2:E2) beside your data, see screenshot:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-hide-blanks-1.png
2. Then, filter the new helper Blank column, hide all 0 value rows, see screenshot:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-hide-blanks-2.png
3. And then, you should hide the new Blank column, and print the data, after printing the worksheet, please cancel the filter to unhide the blank rows as you need.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
When executing the code in office 2013/2019/2021 it works but takes too much time to complete (only 95 rows to hide).
How can you speed this?
Thanks!
This comment was minimized by the moderator on the site
Hi, Asaf,
The code works well in my Excel file, could you upload your attachment worbook here if you don't mind? So that we can help to check the problem.

Thank you!
This comment was minimized by the moderator on the site
How to hide row which contain checkbox?
This comment was minimized by the moderator on the site
Hello, Sweta

To hide rows with checkbox, the below article may do you a favor:
How To Hide Checkbox When Row Is Hidden In Excel?

Please try, if you still have any other question, please comment here.
This comment was minimized by the moderator on the site
If the value in column E is blank or 0 i would like the row to auto hide. If the value in E changes to something other than blank or 0 I would like it to show. Report is 1500 rows
This comment was minimized by the moderator on the site
Hello, Cathy,
To hide the rows automatically based on blank cells or 0 values, please use the below vba code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("E1:E1500")
            If (xRg.Value = "") Or (xRg.Value = "0") Then
                xRg.EntireRow.Hidden = True
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True
End Sub


Please try, hope it can help you!
This comment was minimized by the moderator on the site
I would like to auto hide rows if column E is blank or 0
This comment was minimized by the moderator on the site
This is working great for me, It hides the rows and opens them when my values change based on formulas.  The question I have is my sheet is 104 rows long.  It churns for a bit each time I click a cell.  Any way to speed up the transition when it is activated?  Or is it my computer?Thanks!
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