View Single Post
  #5   Report Post  
duane
 
Posts: n/a
Default Merging Text Help


try this - note you need to name some ranges - it also parses the input
lists so it will move data around

if you need to keep original lists i suggest add a copy command to
another location at the start

Sub macro1()
'list1 and list2 are names of ranges (cells) with the two lists
' named range "output" is destination cell
' first parse both lists
Dim list1(100) As String
Dim list2(100) As String
List1row = Range("list1").Row
list1col = Range("list1").Column
List2row = Range("list2").Row
list2col = Range("list2").Column
Range("list1").Select
Selection.TextToColumns Destination:=Range("list1"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, Comma:=True
Range("list2").Select
Selection.TextToColumns Destination:=Range("list2"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, Comma:=True
' define length of two lists
list1len = Range("list1").End(xlToRight).Column - _
Range("list1").Column
list2len = Range("list2").End(xlToRight).Column - _
Range("list2").Column
For i = 1 To list1len
list1(i) = Cells(List1row, list1col + i - 1).Value
Next i
For i = 1 To list2len
list2(i) = Cells(List2row, list2col + i - 1).Value
Next i
output = ""
For i = 1 To list1len + 1
For j = 1 To list2len + 1
output = output & list1(i) & list2(j) & ", "
Next j
Next i
Range("output").Value = output
End Sub


--
duane


------------------------------------------------------------------------
duane's Profile: http://www.excelforum.com/member.php...o&userid=11624
View this thread: http://www.excelforum.com/showthread...hreadid=482552