+ Reply to Thread
Results 1 to 4 of 4

delete everything but print area

  1. #1

    delete everything but print area

    How can I delete all rows and columns that are outside a worksheets
    print area? Thanks.


  2. #2
    Ron de Bruin
    Guest

    Re: delete everything but print area

    You can try this to hide the rows and columns

    Sub Test()
    Dim rng As Range
    Dim FirstEmptyRow As Long
    Dim FirstEmptyCol As Integer

    With ActiveSheet.PageSetup
    Set rng = Range(.PrintArea)
    End With

    FirstEmptyCol = rng.Cells(rng.Cells.Count).Column + 1
    FirstEmptyRow = rng.Rows.Count + rng.Cells(1).Row

    Range(Cells(1, FirstEmptyCol), Cells(1, 256)).EntireColumn.Hidden = True
    Range(Cells(FirstEmptyRow, 1), Cells(Rows.Count, 1)).EntireRow.Hidden = True
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    <[email protected]> wrote in message news:[email protected]...
    > How can I delete all rows and columns that are outside a worksheets
    > print area? Thanks.
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: delete everything but print area

    Sub DDD()
    Dim rng As Range, lastRow As Long
    Dim lastCol As Long, i As Long
    Dim rw As Range, col As Range
    Set rng = ActiveSheet.UsedRange
    lastRow = rng.Rows(rng.Rows.Count).Row
    lastCol = rng.Columns(rng.Columns.Count).Column
    For i = lastRow To 1 Step -1
    Set rw = Rows(i)
    If Intersect(rw, Range("Print_Area")) Is Nothing Then
    rw.EntireRow.Delete
    End If
    Next
    For i = lastCol To 1 Step -1
    Set col = Columns(i)
    If Intersect(col, Range("Print_Area")) Is Nothing Then
    col.EntireColumn.Delete
    End If
    Next
    ActiveSheet.UsedRange
    End Sub

    --
    Regards,
    Tom Ogilvy



    <[email protected]> wrote in message
    news:[email protected]...
    > How can I delete all rows and columns that are outside a worksheets
    > print area? Thanks.
    >




  4. #4
    Registered User
    Join Date
    11-19-2013
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: delete everything but print area

    is there a way do this for a whole workbook instead of just for the active sheet?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1