Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Bob
 
Posts: n/a
Default Hide Empty Rows When Printing

I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob
  #2   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Try this Bob if they are empty

http://www.rondebruin.nl/print.htm#Hide

See this part

With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = False
On Error GoTo 0
End With

Change .Columns("A") to .Range("A6:A2000")


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


"Bob" wrote in message ...
I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob



  #3   Report Post  
Bob
 
Posts: n/a
Default

This is what I am using now:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Production" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
On Error Resume Next

..Range("A6:A2000").SpecialCells(xlCellTypeBlanks) .EntireRow.Hidden = True
.PrintOut

..Range("A6:A2000").SpecialCells(xlCellTypeBlanks) .EntireRow.Hidden = False
On Error GoTo 0
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

It does not hide the rows, Why?

Thanks,
Bob

"Ron de Bruin" wrote:

Try this Bob if they are empty

http://www.rondebruin.nl/print.htm#Hide

See this part

With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = False
On Error GoTo 0
End With

Change .Columns("A") to .Range("A6:A2000")


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


"Bob" wrote in message ...
I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob




  #4   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Hi Bob

I think your cells in A are not Blank

You can test it like this

=ISBLANK(A1)

Do you have formulas in the A column ?

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


"Bob" wrote in message ...
This is what I am using now:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Production" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
On Error Resume Next

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = True
.PrintOut

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = False
On Error GoTo 0
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

It does not hide the rows, Why?

Thanks,
Bob

"Ron de Bruin" wrote:

Try this Bob if they are empty

http://www.rondebruin.nl/print.htm#Hide

See this part

With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = False
On Error GoTo 0
End With

Change .Columns("A") to .Range("A6:A2000")


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


"Bob" wrote in message ...
I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob






  #5   Report Post  
Bob
 
Posts: n/a
Default

Yes I have a links in every cell in the in the A column to another sheet some
have information showing some don't that is why I am trying to hide them in a
printed report. Is there a way around this to still hide them?

Bob

"Ron de Bruin" wrote:

Hi Bob

I think your cells in A are not Blank

You can test it like this

=ISBLANK(A1)

Do you have formulas in the A column ?

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


"Bob" wrote in message ...
This is what I am using now:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Production" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
On Error Resume Next

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = True
.PrintOut

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = False
On Error GoTo 0
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

It does not hide the rows, Why?

Thanks,
Bob

"Ron de Bruin" wrote:

Try this Bob if they are empty

http://www.rondebruin.nl/print.htm#Hide

See this part

With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = False
On Error GoTo 0
End With

Change .Columns("A") to .Range("A6:A2000")


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


"Bob" wrote in message ...
I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob








  #6   Report Post  
Ron de Bruin
 
Posts: n/a
Default

Hi Bob

Try this macro then to Hide/Print/Unhide
Delete "preview:=True" if it is working correct


Sub Hide_Print_Unhide()
Dim cell As Range
Application.ScreenUpdating = False
With Sheets("Production")
For Each cell In .Range("A6:A2000")
If cell.value = "" Then cell.EntireRow.Hidden = True
Next cell
.PrintOut preview:=True
.Range("A6:A2000").EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub


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


"Bob" wrote in message ...
Yes I have a links in every cell in the in the A column to another sheet some
have information showing some don't that is why I am trying to hide them in a
printed report. Is there a way around this to still hide them?

Bob

"Ron de Bruin" wrote:

Hi Bob

I think your cells in A are not Blank

You can test it like this

=ISBLANK(A1)

Do you have formulas in the A column ?

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


"Bob" wrote in message ...
This is what I am using now:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Production" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
On Error Resume Next

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = True
.PrintOut

.Range("A6:A2000").SpecialCells(xlCellTypeBlanks). EntireRow.Hidden = False
On Error GoTo 0
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

It does not hide the rows, Why?

Thanks,
Bob

"Ron de Bruin" wrote:

Try this Bob if they are empty

http://www.rondebruin.nl/print.htm#Hide

See this part

With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).Entir eRow.Hidden = False
On Error GoTo 0
End With

Change .Columns("A") to .Range("A6:A2000")


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


"Bob" wrote in message ...
I am trying to use this code to hide all empty rows in column A when printing
I would like to start in row 6 an end in row 2000 so my header will print. It
doesn't work can you tell why?

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Production")
For rw = 1 To 2000
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:A2000")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview ' for testing use .PrintPreview
.Range("A1:A2000").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub

Thank you for your help,
Bob








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
Pivot Tables & not printing blank rows (revisited) [email protected] Excel Discussion (Misc queries) 1 August 4th 05 07:42 AM
Format to hide empty rows tamato43 Excel Discussion (Misc queries) 4 May 10th 05 10:16 PM
Can Excel "slide up" rows with content thru empty rows to condense portly44 Excel Worksheet Functions 2 April 1st 05 12:47 AM
how to hide rows in a protected sheet Prakash Excel Worksheet Functions 7 January 18th 05 02:42 PM
Macro to hide rows with empty cells tp58tp Excel Worksheet Functions 2 November 13th 04 02:01 PM


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