Hide Print Unhide

K

Khalil Handal

Hi,
I need a macro (VBA Code) to:
1- unprotect sheet with password="111"
2- HIDE empty rows between 7 and 159 (7, 159 are included)
3- Print the range A4:D160
4- UNHIDE all rows between 7 and 159
5- Protect sheet with password="111"

Recording macro will not work because the empty rows are different each time

Khalil
 
R

Ron de Bruin

Hi Khalil

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

Maybe this one ?
Add you protect en unprotect code lines to the macro

*************************************
Hide Empty rows, Print and unhide the rows

This example will loop through every row in the range
Set rng = Sheets("Sheet1").Range("A1:A30")

If every cell in column A:G is empty it will hide that row.
After the loop it print the sheet and then unhide the rows.

Change "A1:G1" in the macro to the cells you want.
You can also use this with non contiguous ranges like "B1,D1:G1"

Sub Hide_Print_Unhide()
Dim rw As Long
Dim rng As Range
Dim cell As Range

Application.ScreenUpdating = False

Set rng = Sheets("Sheet1").Range("A1:A30")

With rng.Columns(1)
For Each cell In rng
If Application.WorksheetFunction.CountA( _
.Parent.Cells(cell.Row, 1).Range("A1:G1")) = 0 Then _
.Parent.Rows(cell.Row).Hidden = True
Next cell
.Parent.PrintOut
.EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top