ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Print question (https://www.excelbanter.com/excel-programming/347391-print-question.html)

David

Print question
 
Need a Before_Print code that will do the following:
1) Maintain 3 header rows set in "rows to repeat at top"
2) Hide rows that do not contain dates for month in A2, dates start at C4
and go down the column, some of which may not have dates entered yet
3) Print the sheet
4) Unhide the rows previously hidden in 2)

something like
If month(c4:c124)< month(a2) then entirerow.hidden=true
Range(visiblerows).printout
Range(hiddenrows).visible=true

--
David

David

Print question
 
David wrote

something like
If month(c4:c124)< month(a2) then entirerow.hidden=true
Range(visiblerows).printout
Range(hiddenrows).visible=true


more like
If month(c4:c124)< month(a2) OR isempty(cell in range(c4:c124) then ...

--
David

David

BeforePrint help needed
 
Original post seems to have disappeared :(
Need to filter rows before printing, hiding rows that aren't in desired
month or don't have desired date entries in range.

Borrowing from another file I got half of what I want:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
On Error GoTo Quit
Range("D4:C" & Range("Print_Area").Rows.Count).SpecialCells _
(xlCellTypeBlanks).EntireRow.Hidden = True
'<-- Need another line here for handling needed month
Application.OnTime Now(), ThisWorkbook.Name & "!WorkbookAfterPrint"
Quit:
End Sub

Sub WorkbookAfterPrint()
Range("C4:C" & Range("Print_Area").Rows.Count).SpecialCells _
(xlCellTypeBlanks).EntireRow.Hidden = False
'<-- Need another line here for handling needed month
End Sub

I do have a conditional formatting formula set and think it could be
adapted to look at the desired range, but need help with VBA syntax:
=AND(YEAR(D4)=YEAR($A$2),MONTH(D4)=MONTH($A$2))
IOW, how to adapt the formula to VBA

--
David


All times are GMT +1. The time now is 01:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com