VBA Hide empty rows
VBA Telemetry pings you when your VBA projects fail
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: VBA Hide empty rows

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Las Vegas Nevada USA
    Posts
    239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I have a procedure that tests a range and where it finds an empty cell it hides the row. Works instantly upon loading but after printing or even print preview it takes about 20 seconds to run. Any ideas?? Here's the code.

    Public Sub Hide()
    LastRow = ActiveSheet.UsedRange.Row - 1 + _
    ActiveSheet.UsedRange.Rows.Count
    Application.ScreenUpdating = False
    For r = LastRow To 7 Step -1
    If IsEmpty(Range("C" & r).Value) Then
    Rows(r).Hidden = True

    End If

    Next r
    End Sub

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Place this @ the start of your code.

    ActiveSheet.DisplayAutomaticPageBreaks = False

    eg.

    Public Sub Hide()
    ActiveSheet.DisplayAutomaticPageBreaks = False
    LastRow = ActiveSheet.UsedRange.Row - 1 + _
    ActiveSheet.UsedRange.Rows.Count
    Application.ScreenUpdating = False
    For r = LastRow To 7 Step -1
    If IsEmpty(Range("C" & r).Value) Then
    Rows(r).Hidden = True

    End If

    Next r
    End Sub


    HTH

    Ivan

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Las Vegas Nevada USA
    Posts
    239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Ivan I'll give it a try and let you know how it works.

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Las Vegas Nevada USA
    Posts
    239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Hey works grrrrrreat. Thanks again Ivan.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com