Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This assumes the same number of words in each column.
Sub Combinations() Dim i As Long, j As Long Dim k As Long, l As Long Dim rw As Long, s As String Dim s1 As String, s3 As String Dim rwCnt As Long, numwords As Long ' words are in row 1 to rwCnt rwCnt = 3 'specify how many columns of words numwords = 4 rw = 1 For i = 1 To rwCnt For j = 1 To rwCnt s = Cells(i, 1) & " " & Cells(j, 2) If numwords = 2 Then Cells(rw, 3).Value = s: rw = rw + 1 Else For k = 1 To rwCnt s1 = s & " " & Cells(k, 3) If numwords = 3 Then Cells(rw, 4).Value = s1: rw = rw + 1 Else For l = 1 To rwCnt s2 = s1 & " " & Cells(l, 4) Cells(rw, 5).Value = s2: rw = rw + 1 Next l End If Next k End If Next j Next i End Sub It handles two, three or four columns of words. -- Regards, Tom Ogilvy " wrote: Hi, I've found variations of what I'm looking for in the group, but nothing that's an exact fit. I'm trying to produce a macro that would output all combinations of words from multiple lists. So, for example, if a sheet contains the following two lists: A B 1 happy cow 2 sad dog 3 angry cat The code would produce the following list in Column C (words separated by a space). C 1 happy cow 2 happy dog 3 happy cat 4 sad cow 5 sad dog 6 sad cat 7 angry cow 8 angry dog 9 angry cat The macro should be able to perform this routine for two, three, or four columns of words (placing the completed list in the column immediately to the right of the last list). Any ideas how to do this? Thanks! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
combining text | Excel Discussion (Misc queries) | |||
Advanced text function (combining text) | Excel Worksheet Functions | |||
Combining Text and Dollar Value | Excel Discussion (Misc queries) | |||
combining text | Excel Worksheet Functions | |||
Combining text | Excel Discussion (Misc queries) |