PC Review


Reply
Thread Tools Rate Thread

How to create a table of multiple combination

 
 
amirstal
Guest
Posts: n/a
 
      22nd Jan 2012
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.
 
Reply With Quote
 
 
 
 
James Ravenswood
Guest
Posts: n/a
 
      22nd Jan 2012
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

 
Reply With Quote
 
Auric__
Guest
Posts: n/a
 
      22nd Jan 2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


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