• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code to hide columns - can it be improved?

David Evans

Active Member
Code:
Sub SummaryHideRows()
Debug.Print "SummaryHideRows"
ThisWorkbook.Sheets("Summary").Select
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Cells.EntireRow.Hidden = False
Dim c As Range
        For Each c In Range("A9:A83")
            If Left(c.Value, 5) = "Acct." Then Rows(c.Row).Hidden = True
        Next
Application.ScreenUpdating = True
End Sub

I use the above code and variations of it to hide unwanted columns/rows in our worksheet. Does anyone have any thoughts on how the code can be improved/speeded up! Not that i's awfully slow, but as we us this a good deal, every little bit helps ..

I was thinking of canning the loop and using an array to define the range ...
 
Code:
Sub HidebyArray()
Dim HideArray As Variant
Dim i As Integer
Dim r As Integer
HideArray = ThisWorkbook.Sheets("Summary").Range("Acct1to75").Value
Application.ScreenUpdating = False
For i = LBound(HideArray) To UBound(HideArray)
r = i + 8
If Left(HideArray(i, 1), 5) = "Acct." Then
ThisWorkbook.Sheets("Summary").Rows(r).Hidden = True
End If
Next i
Application.ScreenUpdating = True
End Sub

OK - FYI - this is what I came up with this afternoon in an attempt to amuse myself ...
 
Back
Top