Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
darkshadow91223
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

a1
b2
c3
d4
 5
 6
 7
 8
 9
 10
 11

 

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
	next
	
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.

Labels (2)
2 Replies
marcus_sommer

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

cwolf
Creator III
Creator III

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

Correct:

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