PC Review


Reply
Thread Tools Rate Thread

Concatenate All Possible Combinations

 
 
Kevin199
Guest
Posts: n/a
 
      6th Oct 2009
I have a spreadsheet with 2 columns. I would like to concatenate each row in
column A with all rows in column B into another sheet. The columns are
different lengths and are between 50 and 150 rows long.
Example:
Column A Column B
Dog Red
Cat Brown
Sheep Yellow
Horse

In sheet 2
Column A
Dog – Red
Dog – Brown
Dog – Yellow
Cat – Red
Cat – Brown
Cat – Yellow
Sheep – Red
Sheep – Brown
Sheep – Yellow
Horse – Red
Horse – Brown
Horse - Yellow
Help please. Thank you.

 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      6th Oct 2009
Sub MixAndMatch()
Dim s1 As Worksheet
Dim s2 As Worksheet
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
s1.Activate
i = Cells(Rows.Count, "A").End(xlUp).Row
j = Cells(Rows.Count, "B").End(xlUp).Row
k = 1
For ii = 1 To i
v1 = Cells(ii, 1).Value
For jj = 1 To j
s2.Cells(k, 1).Value = v1 & "-" & s1.Cells(jj, 2).Value
k = k + 1
Next
Next
End Sub
--
Gary''s Student - gsnu200906


"Kevin199" wrote:

> I have a spreadsheet with 2 columns. I would like to concatenate each row in
> column A with all rows in column B into another sheet. The columns are
> different lengths and are between 50 and 150 rows long.
> Example:
> Column A Column B
> Dog Red
> Cat Brown
> Sheep Yellow
> Horse
>
> In sheet 2
> Column A
> Dog – Red
> Dog – Brown
> Dog – Yellow
> Cat – Red
> Cat – Brown
> Cat – Yellow
> Sheep – Red
> Sheep – Brown
> Sheep – Yellow
> Horse – Red
> Horse – Brown
> Horse - Yellow
> Help please. Thank you.
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      6th Oct 2009
I like that.


Gord

On Mon, 5 Oct 2009 16:37:01 -0700, Gary''s Student
<(E-Mail Removed)> wrote:

>Sub MixAndMatch()
>Dim s1 As Worksheet
>Dim s2 As Worksheet
>Set s1 = Sheets("Sheet1")
>Set s2 = Sheets("Sheet2")
>s1.Activate
>i = Cells(Rows.Count, "A").End(xlUp).Row
>j = Cells(Rows.Count, "B").End(xlUp).Row
>k = 1
>For ii = 1 To i
> v1 = Cells(ii, 1).Value
> For jj = 1 To j
> s2.Cells(k, 1).Value = v1 & "-" & s1.Cells(jj, 2).Value
> k = k + 1
> Next
>Next
>End Sub


 
Reply With Quote
 
Kevin199
Guest
Posts: n/a
 
      7th Oct 2009
Works great thank you very much!!

"Kevin199" wrote:

> I have a spreadsheet with 2 columns. I would like to concatenate each row in
> column A with all rows in column B into another sheet. The columns are
> different lengths and are between 50 and 150 rows long.
> Example:
> Column A Column B
> Dog Red
> Cat Brown
> Sheep Yellow
> Horse
>
> In sheet 2
> Column A
> Dog – Red
> Dog – Brown
> Dog – Yellow
> Cat – Red
> Cat – Brown
> Cat – Yellow
> Sheep – Red
> Sheep – Brown
> Sheep – Yellow
> Horse – Red
> Horse – Brown
> Horse - Yellow
> Help please. Thank you.
>

 
Reply With Quote
 
Mark Livingstone
Guest
Posts: n/a
 
      7th Oct 2009
How about if I just have 1 Column with numbers:

1
2
3
4

and would like all possible combinations? (12, 21, 13, 31, etc..)
could you please tweak your code to that that?

thanks!!!
 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combinations =?Utf-8?B?Q2hyaXNfdF8yazU=?= Microsoft Excel Misc 2 7th Feb 2006 10:36 AM
I know how to concatenate ,can one de-concatenate to split date? =?Utf-8?B?UVVJQ0sgQk9PS1MgUFJPQkxFTS0=?= Microsoft Excel New Users 1 26th Jul 2005 05:07 PM
Combinations Don Lloyd Microsoft Excel Programming 2 29th Jun 2005 07:14 AM
combinations Stephen R Microsoft Excel Discussion 10 24th Jun 2005 09:52 PM
Combinations Ben Allen Microsoft Excel Programming 5 29th Mar 2004 06:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.