Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Hawk,
Insert a standard module into the workbook holding the data and reporting sheets and copy / paste the following code: Option Explicit Public Const PWORD As String = "opensaysme" '<<====CHANGE!! '================================ Sub PrintDataSheet() With ThisWorkbook.Sheets("Box") .Unprotect Password:=PWORD Call Hide_EmptyColumns .PrintOut Call Unhide_EmptyColumns .Protect Password:=PWORD End With End Sub '<<================================= '================================= Sub Hide_EmptyColumns() 'To hide columns with no data in rows 10:82 Dim col As Range Application.ScreenUpdating = False With ThisWorkbook.Sheets("Box") For Each col In .Range("C10:AF82").Columns col.EntireColumn.Hidden = _ Application.Sum(col) = 0 Next End With Application.ScreenUpdating = True End Sub '================================ '<<================================ Sub Unhide_EmptyColumns() 'To Unhide columns with no data in rows 10:82 Application.ScreenUpdating = False With ThisWorkbook.Sheets("Box") .Range("C10:AF82").Columns. _ EntireColumn.Hidden = False End With Application.ScreenUpdating = True End Sub '================================= Add a Commandbutton (from the Controls Toolbar) to the Box sheet. Give the CommandButton a suitable caption (Print Report, say). DoubleClick the button and between the lines: Private Sub CommandButton1_Click() and End Sub insert the line: Call PrintDataSheet Hit Alt-F11 to return to Excel. Press the button ... Read the printed report. PS Make sure that you replace the password from "opensaysme" to your own password text. --- Regards, Norman "Hawk" wrote in message ups.com... Thanks Norman!!! It worked...two more questions: (1) Actually, the macro worked before I protected my worksheet, however, once I apply the protection I get a run time error because I have set the protection settings to not allow the hiding of columns or rows. (2) I only want to hide the empty columns for the purposes of printing, can you tell me what to add to the end of the code so that the hidden columns become visible again after printing? Can you insert the necessary lines of code that I need to accomplish the 2 points above and paste the entire routine in your response? Also, I plan to link this macro to a button that will be on the data entry sheet. Currently, I have the code on Module 1...is that where it should be for printing purposes? Thanks again for you help!!! You just don't know how many countless hours I've spent on this... |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Hide Rows or Columns with +/- button above row/column label headin | Excel Worksheet Functions | |||
Macro to hide rows with zero values in columns | Excel Discussion (Misc queries) | |||
Help on Macro to hide empty rows | Excel Discussion (Misc queries) | |||
Macro to hide/show rows and columns | Excel Discussion (Misc queries) | |||
Macro to hide rows with empty cells | Excel Worksheet Functions |