View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
squenson via OfficeKB.com squenson via OfficeKB.com is offline
external usenet poster
 
Posts: 78
Default Combining Text in Columsn

Here is a macro that does it for up to 6 columns. The list of words starts in
row 1 and there should not be blank. Results are copied in column G.

Sub GenerateSentences()

Dim i1 As Long
Dim i2 As Long
Dim i3 As Long
Dim i4 As Long
Dim i5 As Long
Dim i6 As Long

i1 = 1
i2 = 1
i3 = 1
i4 = 1
i5 = 1
i6 = 1
j = 1
While Cells(i1, 1) < "" Or i1 = 1
While Cells(i2, 2) < "" Or i2 = 1
While Cells(i3, 3) < "" Or i3 = 1
While Cells(i4, 4) < "" Or i4 = 1
While Cells(i5, 5) < "" Or i5 = 1
While Cells(i6, 6) < "" Or i6 = 1
Cells(j, 7) = Trim(Cells(i1, 1) & _
" " & Cells(i2, 2) & " " & Cells(i3, 3) & " " & _
Cells(i4, 4) & " " & Cells(i5, 5) & " " & Cells(i6, 6))
j = j + 1
i6 = i6 + 1
Wend
i6 = 1
i5 = i5 + 1
Wend
i5 = 1
i4 = i4 + 1
Wend
i4 = 1
i3 = i3 + 1
Wend
i3 = 1
i2 = i2 + 1
Wend
i2 = 1
i1 = i1 + 1
Wend

End Sub


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!


--
Message posted via
http://www.officekb.com