Lauren has attended:
Excel VBA Introduction course
Print on PDF columns with "Y" on the top row - Ignore has been
Hi,
Please ignore query below. I have resolved the issue. Thank you.
Hi,
I have a macro which prints columns with data relating to a specific entity as long as the top row has a "Y". It prints the title rows 5 to 7 and column A with the descriptions.
I have made some changes to the file in that I added more data in each column and now there are more rows to print.
The original macro is as follows:
when I ran it, it doesn't work.
Please could you explain what is doing in the commands I put "please explain" in brackets to see what I need to change.
(PLEASE EXPLAIN): Please could you explain step by step what is doing here?
Dim UsedR As Integer
UsedR = Cells(Rows.Count, "A").End(xlUp).Row - 5
Rows("7:" & UsedR).Select
Selection.AutoFilter
Cells(1, 2).Activate
(ok, it is setting up the page to print)
With ActiveSheet.PageSetup
.PrintTitleRows = "$5:$7"
.PrintTitleColumns = "$A:$A"
.Orientation = xlPortrait
.PaperSize = xlPaperA4
.Order = xlDownThenOver
.BlackAndWhite = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
(ok, it is asking for information and formatting)
Ans = MsgBox("The header for this document is currently set as:" & vbNewLine & "'" & ActiveSheet.PageSetup.CenterHeader & "'" & vbNewLine & "Is this correct?", vbYesNo)
If Ans = vbNo Then
Header = InputBox("Please enter the new header for the backing documentation")
ActiveSheet.PageSetup.CenterHeader = Header
ActiveSheet.PageSetup.LeftHeader = "&""Calibri,Bold""&12&P"
End If
(PLEASE EXPLAIN) I suppose it is saying if there is a "N" in the first row then do nothing, else print. Please could you explain step by step what is asking to do below?
Dim i As Integer
For i = 2 To ActiveSheet.UsedRange.Columns.Count
Cells(1, i).Activate
If ActiveCell.Value = "N" Then
ActiveCell.Offset(0, 1).Activate
ElseIf ActiveCell.Offset(UsedR, 0).Value = 0 Then
ActiveCell.Offset(0, 1).Activate
ElseIf ActiveCell.Value = "Y" Then
Unit = ActiveCell.Offset(4, 0).Value
ActiveCell.Offset(6, 0).Select
Selection.AutoFilter Field:=i, Criteria1:="<>0"
ActiveCell.Offset(-2, 0).Activate
ActiveCell.Range("A1:A" & UsedR - 1).Select
With Selection
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Directory & "\" & Unit & " - " & Period & ".pdf", _
OpenAfterPublish:=False
End With
Selection.AutoFilter Field:=i
End If
Next i
The macro is not working for me in that it prints a column, say column AD and then jumps to column FL to the very end when there is no data. The top row have Y or N.
Thank you and Kind Regards,
Lauren
RE: Print on PDF columns with "Y" on the top row - Ignore has b
Hi Lauren,
Glad you managed to resolve yourself, well done.
Kind regards
Richard
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector