Consulting

Results 1 to 4 of 4

Thread: Solved: Trimming Things Down...

  1. #1
    VBAX Contributor compariniaa's Avatar
    Joined
    Jun 2006
    Location
    Santa Clarita, CA
    Posts
    117
    Location

    Solved: Trimming Things Down...

    I have over 2,000 entries in one spreadsheet, with revenue figures in column
    H, and the figures are sorted ascending
    To provide the user with a quick overview on a printout, I wanted to
    "compress" everything so it would fit onto one landscape-oriented page. By
    compress I mean hide the middle values, not zoom out. By hiding the middle
    values, only the biggest losers and the biggest gainers are shown.
    How could I write a sub that kept hiding the middle rows until only 50 rows are visible?

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hello,

    Take a look at the following, should be what you need:[vba]Sub compariniaa()
    With ActiveSheet.UsedRange
    If .Rows.Count > 50 Then
    .Range(.Rows(26), .Rows(.Rows.Count - 25)).EntireRow.Hidden = True
    End If
    End With
    End Sub[/vba]Please let me know if its not what you're looking for!
    Matt

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This should show the top and bottom 25 values, whether the data is sorted or not.
    Regards
    MD
    [VBA]Sub Ranks()
    Dim MyRange As Range
    Set MyRange = Intersect(Columns(8), ActiveSheet.UsedRange)
    Application.ScreenUpdating = False
    For Each cel In MyRange
    If Application.WorksheetFunction.Rank(cel, MyRange) < MyRange.Cells.Count - 25 And _
    Application.WorksheetFunction.Rank(cel, MyRange) > 25 Then
    cel.RowHeight = 0
    End If
    Next
    Application.ScreenUpdating = True
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Contributor compariniaa's Avatar
    Joined
    Jun 2006
    Location
    Santa Clarita, CA
    Posts
    117
    Location
    Matt and MD, that's excellent! That's exactly what I needed, thank you very much for your help

Posting Permissions

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