Martin,

I can't thank you enough for this program. I wonder if I can ask you for one more favour... in your current program variable 5 has the largest number of states. I tried running the same program, slightly modified to have 2, 4 and 3 states for 3 variables only. In this example I get the following output:

V1S1 V2S1 V3S1
V1S1 V2S1 V3S2
V1S1 V2S1 V3S3
V1S1 V2S1
V1S1 V2S2 V3S1
V1S1 V2S2 V3S2
V1S1 V2S2 V3S3
V1S1 V2S2
V1S1 V2S3 V3S1
V1S1 V2S3 V3S2
V1S1 V2S3 V3S3
V1S1 V2S3
V1S1 V2S4 V3S1
V1S1 V2S4 V3S2
V1S1 V2S4 V3S3
V1S1 V2S4
V1S2 V2S1 V3S1
V1S2 V2S1 V3S2
V1S2 V2S1 V3S3
V1S2 V2S1
V1S2 V2S2 V3S1
V1S2 V2S2 V3S2
V1S2 V2S2 V3S3
V1S2 V2S2
V1S2 V2S3 V3S1
V1S2 V2S3 V3S2
V1S2 V2S3 V3S3
V1S2 V2S3
V1S2 V2S4 V3S1
V1S2 V2S4 V3S2
V1S2 V2S4 V3S3
V1S2 V2S4

I believe this is because the MaxStates variable is set to 4 (which is the largest number of states in any variable). How can the code be altered so that it doesn't matter which variable has the largest number of states? The output shouldn't contain blank cells.

Thanks again.

Mbrolass.