简体   繁体   中英

Hide blank rows on all worksheets on an Excel workbook

I have a workbook with about 25 worksheets. And I want a macro to hide any rows (from 5 to 33) if there is nothing (number or text) in the column A of that row.

Can someone help please?

I have seen similar ones deleting blank rows ect. But I am not smart enough to change those to fit. If you could give me the code I can copy it on to my file (VBA).

Please help... Thanks

Sub Hiderow() 
    Application.ScreenUpdating = False 
    Dim s As String 

    For i = 1 To Range("A5:A33").Count 
        s = i & ":" & i 
          If IsEmpty(Cells(i, 1).Value) Then Rows(s).EntireRow.Hidden = True 
    Next 

    Application.ScreenUpdating = True 
End Sub

Loop each sheet then loop rows 5 to 33 in each worksheet.

Sub Hiderow()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    'Loop each worksheet
    For Each ws In ThisWorkbook.Worksheets
        'make sure the ranges refer to the correct sheet
        With ws
            'Loop the rows
            For i = 5 To 33
                'Set hidden status based on whether there is a visible value in column A
                .Rows(i).Hidden = .Cells(i, 1) = ""
            Next
        End With
    Next ws
    Application.ScreenUpdating = True
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM