Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
444sofiane
Contributor II
Contributor II

Loop Macro

Hello Everybody,

I tried to do a macro pressing x times a button (here x is a field selection in a table of values)
but when i use a non constant variable (here v) in the loop for it doesn't work for some reason :

sub Active


set v=ActiveDocument.Fields("NbValues").GetSelectedValues
if v.Count > 0 then
    for i=1 to v
        ActiveDocument.GetSheetObject("BU09").Press
       for j=1 to 1000
       next
    next
end if


end Sub

Any idea how to solve this ?

Labels (2)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

ActiveDocument.Fields("NbValues").GetSelectedValues returns an Array so you would have to select an array item and get it's value. To get the value of the first item:

v.Item(0).Number

You may find it simpler to use the Evaluate function which allows you to use Qlik expressions. 

for i=1 to ActiveDocument.Evaluate("=Min(NbValues)")

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

4 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

for i=1 to v.Count

-Rob

444sofiane
Contributor II
Contributor II
Author

Hello Rob 

I would like to stop the for loop when I reach the value in field "NbValues" not when I reach the Number of Selections in the ffield "NbValues" dont know if its clear 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

ActiveDocument.Fields("NbValues").GetSelectedValues returns an Array so you would have to select an array item and get it's value. To get the value of the first item:

v.Item(0).Number

You may find it simpler to use the Evaluate function which allows you to use Qlik expressions. 

for i=1 to ActiveDocument.Evaluate("=Min(NbValues)")

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

444sofiane
Contributor II
Contributor II
Author

It works thank you very much Rob

Sautations

Sofiane