Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Talk to Experts Tuesday, Live Q&A, September 22: Moving from QlikView to Qlik Sense. REGISTER
Showing results for 
Search instead for 
Did you mean: 
Contributor III
Contributor III

Macro looping through two fields.

Hi all,

I have this requirement in macro explained below.

I have this:

 Field 1        Field 2



Field 1 is the main field with satatic 4 values. Field 2 subfield of F1, each value in F1 has 11 elements in F2 .

The only thing i need to do is loop through F1 value A and loop in all F2 and then pass to the next element in F1 and so...

My code is this:




Sub importantLoop
	set x=ActiveDocument.Fields("Field1").GetPossibleValues
	For u=0 to x.count-1
		ActiveDocument.Fields("Field1").Select x.item(u).Text
End Sub




but when i ran it, it olny select the first value in F1, 4 times (i need to add the second field)

any idea?. also, both F1 and F2 are string values.

Thanks in advanced.

2 Replies
MVP & Luminary
MVP & Luminary

From a pure loop point of view you will need a second loop within the first one - it's completely the same logic just nesting one within the another. But I think it will be rather not useful in the end because the fields are in general independent of each other and only if each fieldvalue from field 1 has the same number of sub-values in field 2 and those values are also always the same such loop will work.

Therefore I think you need to loop through a table of both fields - within the following link is an example how it could be done: Export-to-CSV-with-quotation-marks.

- Marcus

Creator III
Creator III

For u=0 to x.count-1
     ActiveDocument.Fields("Field1").Select x.item(i).Text


For i=0 to x.count-1
     ActiveDocument.Fields("Field1").Select x.item(i).Text