LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default URGENT!! Use macro button to hide empty columns and rows...HELP!!!!

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
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
Hide Rows or Columns with +/- button above row/column label headin WA Excel Worksheet Functions 3 April 5th 23 02:42 PM
Macro to hide rows with zero values in columns K Dawson Excel Discussion (Misc queries) 2 March 23rd 10 03:00 PM
Help on Macro to hide empty rows nLeBlanc21 Excel Discussion (Misc queries) 4 January 19th 10 10:04 PM
Macro to hide/show rows and columns Leo Excel Discussion (Misc queries) 4 May 23rd 06 05:25 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 06:54 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"