Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Printing Only Rows With Values In Them Options

In order to avoid printing empty rows or just to hide them temporarily
I use this macro "Squeeze_Lines".

Mark the area with the unwanted rows and then start the macro. All
rows in the selection with data will remain visible. The rest will be
grouped and collapsed. Formulas with result=0 will be hidden too.

Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey
As Long) As Integer

Sub Squeeze_Lines()
Dim i As Integer
Dim e As Integer
Dim j As Integer
Dim f As Integer
Dim h As Integer
Dim n As Integer
Dim m As Integer
Dim d As Boolean
Dim s As Boolean
Dim sf As Boolean
Dim thin_rows As Boolean

If Key_pressed(vbKeyShift) Then
sf = True ' the shift key switches off the grouping, rows
will only be hidden
End If
If Key_pressed(vbKeyControl) Then
thin_rows = True
End If

If Not ActiveWorkbook Is Nothing Then
i = Selection.Row ' start row
e = Selection.Row + Selection.Rows.Count - 1
j = Selection.Column
f = Selection.Column + Selection.Columns.Count - 1

If e = Columns(j).EntireColumn.Rows.Count Then
e = LastCell(ActiveSheet).Row
End If

If f = Rows(i).EntireRow.Columns.Count Then
f = LastCell(ActiveSheet).Column
End If

If (e - i) * (f - j) 100000 Then
If MsgBox("You've selected more than 100,000 cells." & Chr
(10) & _
"Please be patient or cancel now.", vbOKCancel)
= vbCancel Then
Exit Sub
Else
Application.ScreenUpdating = False
End If
End If

If Rows(i + 1).RowHeight = Rows(i).RowHeight Then
h = 3 ' if first 2 rows are equal height -squeeze
height is set = 3 points
Else ' otherwise height of the 2nd row is copied to other
empty rows
h = Rows(i + 1).RowHeight
End If
For n = i To e
d = False
For m = j To f
If IsError(Cells(n, m)) Then
d = True
s = False
Exit For
Else
If Cells(n, m).Value < Empty Then
d = True
s = False
Exit For
End If
End If
Next m
If s = True And d = False Then
If sf Then
Rows(n).EntireRow.Hidden = True
Else
Rows(n).Group
End If
ElseIf d = False Then
If thin_rows Then
Rows(n).RowHeight = h
Else
Rows(n).Group
End If
s = True
Else
s = False
End If
Next n
If Not sf Then ActiveSheet.Outline.ShowLevels RowLevels:=1
End If
End Sub

Function Key_pressed(key_to_check As Long) As Boolean
If GetAsyncKeyState(key_to_check) And &H8000 Then
Key_pressed = True
Else
Key_pressed = False
End If
End Function
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
Printing Only Rows With Values In Them robzrob Excel Worksheet Functions 2 December 13th 09 06:58 PM
Printing Options Coverton Excel Worksheet Functions 3 December 16th 08 06:38 PM
How do I omit rows containing nozero values when printing in excel brad Excel Discussion (Misc queries) 4 April 20th 05 10:15 PM
Printing only rows with values - newbie question Tom Ogilvy Excel Programming 0 September 15th 04 01:43 PM
Printing only rows with values - newbie question Bernie Deitrick Excel Programming 0 September 15th 04 01:37 PM


All times are GMT +1. The time now is 11:17 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"