Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default delete everything but print area

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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


wrote in message oups.com...
How can I delete all rows and columns that are outside a worksheets
print area? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



wrote in message
oups.com...
How can I delete all rows and columns that are outside a worksheets
print area? Thanks.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
set area in excel not giving me option to set print area? J Littlebear Excel Discussion (Misc queries) 4 April 23rd 23 09:04 PM
File, print area, clear area, is not working cblind New Users to Excel 2 September 12th 07 04:51 PM
How do you turn off a print area for a page? (no print area) Grunen Excel Discussion (Misc queries) 4 October 8th 05 07:46 PM
Macro to delete columns and set print area twaccess[_12_] Excel Programming 2 July 6th 04 01:34 PM
Identify and Delete all Rows and Columns NOT in Print Area Keith Young[_2_] Excel Programming 6 December 4th 03 04:36 PM


All times are GMT +1. The time now is 07:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"