How can I delete all rows and columns that are outside a worksheets
print area? Thanks.
How can I delete all rows and columns that are outside a worksheets
print area? Thanks.
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
<bodhi2.71828@gmail.com> wrote in message news:1138914676.528718.167140@f14g2000cwb.googlegroups.com...
> How can I delete all rows and columns that are outside a worksheets
> print area? Thanks.
>
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
<bodhi2.71828@gmail.com> wrote in message
news:1138914676.528718.167140@f14g2000cwb.googlegroups.com...
> How can I delete all rows and columns that are outside a worksheets
> print area? Thanks.
>
is there a way do this for a whole workbook instead of just for the active sheet?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks