ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to create a table of multiple combination (https://www.excelbanter.com/excel-programming/445285-how-create-table-multiple-combination.html)

amirstal[_2_]

How to create a table of multiple combination
 
I'd appreciate your help with creating this table.

I have the following data in the following cells (for example - the
real table is much longer):
A1 USD
A2 EUR
A3 GBP
A4 JPY
A5 CHF

I'd like to create a list of all possible combination of 2 cells
combined, e.g., USDEUR, USDGBP, USDJPY, USDCHF, EURGBP, EURJPY,
EURCHF, GBPJPY, GBPCHF and JPYCHF. The new created table should avoid
repetition of a combination that was already created (USDEUR and
EURUSD for example). And the new table should be in a single column if
possible.

Thanks.

James Ravenswood

How to create a table of multiple combination
 
How about:

Sub Combine()
Dim I As Long, J As Long, N As Long, K As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
K = 1
For I = 1 To N
v1 = Cells(I, 1)
For J = I + 1 To N
Cells(K, 2).Value = v1 & Cells(J, 1).Value
K = K + 1
Next
Next
End Sub

This will produce:

USDEUR
USDGBP
USDJPY
USDCHF
EURGBP
EURJPY
EURCHF
GBPJPY
GBPCHF
JPYCHF


Auric__

How to create a table of multiple combination
 
James Ravenswood wrote:

How about:

Sub Combine()
Dim I As Long, J As Long, N As Long, K As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
K = 1
For I = 1 To N


This line needs to be changed to this:
For I = 1 To N - 1

v1 = Cells(I, 1)
For J = I + 1 To N
Cells(K, 2).Value = v1 & Cells(J, 1).Value
K = K + 1
Next
Next
End Sub

This will produce:

USDEUR
USDGBP
USDJPY
USDCHF
EURGBP
EURJPY
EURCHF
GBPJPY
GBPCHF
JPYCHF


--
You have been killed by a stick of butter.


All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com