Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I have this requirement in macro explained below.
I have this:
Field 1 Field 2
a | 1 |
b | 2 |
c | 3 |
d | 4 |
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.
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
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