Skip to main content
MAINTENANCE ALERT: Dec. 12th starting 9 AM CET. Community will be read-only. GET DETAILS
Showing results for 
Search instead for 
Did you mean: 
Not applicable

loop and print selection


I have a pivot table which displays information about sales, variance, profit etc. Those information are based on a department selection, so for example when user selects frozen department, it will display information only about that department. There are about 10 departments overall.

Is it possible to create a button, which will loop through those 10 departments, and print out sheet with pivot table for each department?


11 Replies
Master II
Master II

Well, you can create a report for that dimension and then create a macro that outputs the report for each values. The macro could then be triggered by a button.

Not applicable

I'm not really sure how to create macro that outputs the report for each value. Could you point out some reference where I could find more information about it? I searched to forum but didn't find much information relevant to solve my problem

Thank you

Master II
Master II

See these posts, they're not exactly the same but may help point you in the right direction.

Also, take a look at the API Guide; that should have a lot more information on macro syntax for automating reports.


Not applicable

Thank you,

I will definetly look through those, and post my solution next week. Thanks

Not applicable

Install PDFCreator

Add a button on your report.

Set the Actions to Run Macro. Set the Macro Name property to PrintObjectToPDFForEachValue

Click Edit Module...

Paste this in:

Sub PrintObjectToPDFForEachValue
Dim WSHShell
set objSheet =ActiveDocument.Sheets("NAME OF SHEET YOU ARE PRINTING")
Set val=ActiveDocument.Fields("NAME OF FIELD YOU ARE LOOPING THROUGH").GetPossibleValues(20000)

For i = 1 to Val.count - 1

ActiveDocument.Fields("NAME OF FIELD YOU ARE LOOPING THROUGH").Select val.item(i).Text

Set WSHShell = CreateObject("WScript.Shell")
filename = val.item(i).Text & "_Report.pdf"
RegKey = "HKEY_CURRENT_USER\Software\PDFCreator\Program\"
WSHShell.RegWrite RegKey & "UseAutosave", 1, "REG_SZ"
WSHShell.RegWrite RegKey & "AutosaveFilename", filename, "REG_SZ"
WSHShell.RegWrite RegKey & "SaveFilename", filename, "REG_SZ"

ActiveDocument.GetApplication.Sleep 5000
ActiveDocument.GetSheetObject( "NAME OF OBJECT YOU ARE PRINTING" ).PrintEx "PDFCreator"

ActiveDocument.GetApplication.Sleep 5000

WSHShell.RegWrite RegKey & "AutosaveFilename", "", "REG_SZ"
WSHShell.RegWrite RegKey & "SaveFilename", "", "REG_SZ"
WSHShell.RegWrite RegKey & "UseAutosave", 0, "REG_SZ"

Set WSHShell = nothing
msgbox "done"
end sub

Not applicable

Just for those looking at this post after 2010, for QlikView 11.2 SR5 (12235) you can make use of a Print Report Action and then use banding within the report to loop through the values within the dimension (in this question, that would be department).

As per the help file:


This tab contains properties for banded output of the page. This means that the page is printed repeatedly for each possible value in a specified field.

When the check box Loop Page Over Possible Values in Field is marked, the page will be printed repeatedly while selecting each possible value in the field specified in the drop-down box below. If there are no possible values in the specified field, nothing will be printed. Note that if a selection loop has been specified also on the report level (see the The Selections Tab) you may face a situation where the report selection excludes all values in the page level loop variable. The page will then be skipped for that report loop value. After completed printing, the original selections will be re-applied. If page numbers are used, these will be continuous over all pages printed.



Partner - Contributor III
Partner - Contributor III


I need to suppress blank pages.  Blanks happen when one of the values I band over does not return any values and the graph is blank in QV.

I tried adding a calculation condition to the table but then get the "Calculation Condition not met" printed on the "empty" page.

The I tried the same as the above but with no Caption, same result as above, except now without table headings.

Then I added a Conditional Show expression on the Layout tab for every item on the report, that resulted in the same number of pages, but now the ones I wanted to be suppressed were printing blank.

This could be a solution if you are not using page numbers and remove the blank pages from the printed report (atleast you can reuse those pages again ).

Will keep on trying and let you know if I get it figured out...

Let me know if you get to suppress the "empty" pages



You know some condition that disables the field by which you select the different reports?

You could make an extra field in script, with only the values you want to loop.

original_field  report_field

A                  A

B                  B


Partner - Contributor III
Partner - Contributor III

Do you mean I must do a check for Nulls in the field the report loops over, and then create a report lookup temp table...?