Develop a loop based on a tables characteristics

Luthius

Active Member
Joined
Apr 5, 2011
Messages
324
I need assistance to develop a loop based on these 2 tables below.
The first row contains the values that will repeat along the table.

For the first table each value will repeat 04 times.
For The second table the values will repeat 05 times.

Table01
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]O[/TD]
[/TR]
[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]-[/TD]
[/TR]
[TR]
[TD="align: center"]-[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]-[/TD]
[/TR]
[TR]
[TD="align: center"]-[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]O[/TD]
[/TR]
[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]L[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]O[/TD]
[/TR]
[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]K[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]O[/TD]
[/TR]
[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]M[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]O[/TD]
[/TR]
</tbody>[/TABLE]

table02
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]-[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]U[/TD]
[/TR]
[TR]
[TD="align: center"]P[/TD]
[TD="align: center"]Q[/TD]
[TD="align: center"]R[/TD]
[TD="align: center"]S[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]-[/TD]
[/TR]
</tbody>[/TABLE]

The result will be the values from Table01 and Table02. 15 distinct values in each row.

Results
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]N[/TD]
[TD]P[/TD]
[TD]R[/TD]
[TD]S[/TD]
[TD]T[/TD]
[TD]U[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]F[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]L[/TD]
[TD]M[/TD]
[TD]N[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]S[/TD]
[TD]T[/TD]
[TD]U[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]D[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[TD]O[/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]S[/TD]
[TD]T[/TD]
[TD]U[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]G[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]N[/TD]
[TD]O[/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]T[/TD]
[TD]U[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]E[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]K[/TD]
[TD]M[/TD]
[TD]N[/TD]
[TD]O[/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]S[/TD]
[TD]U[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]J[/TD]
[TD]M[/TD]
[TD]O[/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]S[/TD]
[TD]T[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is this what you mean?
Formula is copied across and down

Excel Workbook
ABCDEFGHIJKLMNO
1ABCDEFGHIJKLMNO
2AB-DEF-HI-KL-N-
3-BCD-F-HIJ-LMN-
4--CD-FG-IJKLM-O
5A--DE-G-IJKL-NO
6ABC-E-GH--K-MNO
7ABC-EFGH-J--M-O
8
9PQRSTU
10P-RSTU
11-QRSTU
12PQ-STU
13PQR-TU
14PQRS-U
15PQRST-
16
17
18ABDEFHIKLNPRSTU
19BCDFHIJLMNQRSTU
20CDFGIJKLMOPQSTU
21ADEGIJKLNOPQRTU
22ABCEGHKMNOPQRSU
23ABCEFGHJMOPQRST
Table Values



Or if you have the CONCAT function in your Excel version, this one.

Excel Workbook
ABCDEFGHIJKLMNO
1ABCDEFGHIJKLMNO
2AB-DEF-HI-KL-N-
3-BCD-F-HIJ-LMN-
4--CD-FG-IJKLM-O
5A--DE-G-IJKL-NO
6ABC-E-GH--K-MNO
7ABC-EFGH-J--M-O
8
9PQRSTU
10P-RSTU
11-QRSTU
12PQ-STU
13PQR-TU
14PQRS-U
15PQRST-
16
17
18ABDEFHIKLNPRSTU
19BCDFHIJLMNQRSTU
20CDFGIJKLMOPQSTU
21ADEGIJKLNOPQRTU
22ABCEGHKMNOPQRSU
23ABCEFGHJMOPQRST
Table Values (2)
 
Upvote 0
Thanks for your amazing formula and efforts as well. But the idea is develop a VBA Loop to do this.
Thanks again
 
Upvote 0
How about
Code:
Sub Luthius()
   Dim Ary1 As Variant, Ary2 As Variant, Nary As Variant
   Dim r As Long, c As Long, cc As Long
   
   Ary1 = Range("A:A").SpecialCells(xlConstants).Areas(1).CurrentRegion.Value2
   Ary2 = Range("A:A").SpecialCells(xlConstants).Areas(2).CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary1), 1 To UBound(Ary1, 2) + UBound(Ary2, 2))
   
   For r = 2 To UBound(Ary1)
      For c = 1 To UBound(Ary1, 2)
         If Ary1(r, c) <> "-" Then
            cc = cc + 1
            Nary(r, cc) = Ary1(r, c)
         End If
      Next c
      For c = 1 To UBound(Ary2, 2)
         If Ary2(r, c) <> "-" Then
            cc = cc + 1
            Nary(r, cc) = Ary2(r, c)
         End If
      Next c
      cc = 0
   Next r
   Range("A20").Resize(r - 1, UBound(Nary, 2)).Value = Nary
End Sub
 
Upvote 0
Unfortunately NOT.
I need to develop a loop to "fill" the values based on 2 set of values using the characteristics of each table shown.

Arr1(1 to 6, 1 to 15)
A pseudo algorithm for the first Array.
01-Get the value from Row#1 and distribute randomly the same value 04 times along 04 Rows of the Array out of 06 rows.
Random Example for the code on first Array Column
Arr(1,1)=Empty
Arr(2,1)=A
Arr(3,1)=A
Arr(4,1)=A
Arr(5,1)=A
Arr(6,1)=Empty

A pseudo algorithm for the Second Array
01-Get the value from Row#1 and distribute randomly the same value 05 times along 05 Rows of the Array out of 06 rows.
Arr2(1 to 6, 1 to 6)
Arr(1,1)=Empty
Arr(2,1)=A
Arr(3,1)=A
Arr(4,1)=A
Arr(5,1)=A
Arr(6,1)=A
The result will be the arrays combined. Total of 15 Columns and 06 Rows. Each column value will be distinct (unique) due the characteristics of the Arrays.
Hope I could explain it better.
 
Last edited:
Upvote 0
I made a mistake on second array explanation. Instead "A" the value is "P" like the table I presented before.

Unfortunately NOT.
I need to develop a loop to "fill" the values based on 2 set of values using the characteristics of each table shown.

Arr1(1 to 6, 1 to 15)
A pseudo algorithm for the first Array.
01-Get the value from Row#1 and distribute randomly the same value 04 times along 04 Rows of the Array out of 06 rows.
Random Example for the code on first Array Column
Arr(1,1)=Empty
Arr(2,1)=A
Arr(3,1)=A
Arr(4,1)=A
Arr(5,1)=A
Arr(6,1)=Empty

A pseudo algorithm for the Second Array
01-Get the value from Row#1 and distribute randomly the same value 05 times along 05 Rows of the Array out of 06 rows.
Arr2(1 to 6, 1 to 6)
Arr(1,1)=Empty
Arr(2,1)=P
Arr(3,1)=P
Arr(4,1)=P
Arr(5,1)=P
Arr(6,1)=P
The result will be the arrays combined. Total of 15 Columns and 06 Rows. Each column value will be distinct (unique) due the characteristics of the Arrays.
Hope I could explain it better.
 
Upvote 0
It would have helped if you had said that from the start and mentioned it again after Peter had provided formulae that compile the result table.
 
Upvote 0
Do you have the top row showing the values to choose from, already in place?
If so where are they?
 
Upvote 0
Firstly apologies for my poor explanation.
Yes, the values are on top row.
I gave as example 21 letters of the alphabet in 2 different tables where these letters are stored in the first row of the tables.
Let's say that:
The first 15 values or letters are on Range(A1:O1) Rng01
The next 06 values or Letters are on Range(R1:X1) Rng02

The loop will go through the first row and repeat the value 04 times for the next 06 rows (randomly position). Then move to the next column doing the same thing until finish the Rng01.
The next loop will Get the value from Row#1 of the Rng02 and distribute randomly the same value 05 times along 05 Rows of the Array out of 06 rows.
Then move to the next column doing the same thing until finish the Rng02.

Ps.: I just need the combination of both loops. Meaning a table with 15 columns and 06 rows where there is no repetition of values between the columns of the same row.
Example:
B C D F H I J L M N Q R S T U
C D F G I J K L M O P Q S T U
 
Upvote 0
Unfortunately I have no idea how to do that. Hopefully someone else will step in and help.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top