Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Onrey
 
Posts: n/a
Default concatenating with unequal columns

I have 3 columns of data that I would like to concatenate to end up with
something like this: T1 APPLE AR
T1 ORANGE AR
T1 BANANA AR and so on, then
T2 APPLE AR
T2 ORANGE AR, etc. showing every possibility of these 3
columns:

Table Product State
T1 APPLE AR
T2 ORANGE NY
T3 BANANA FL
T4 GRAPES
T5 TOMATO
T6
T7

Can anyone help me with this?

Thanks! (in advance)
  #2   Report Post  
Rowan
 
Posts: n/a
Default

You could use a macro to do this. Assuming your data is in Columns A,B and C
with the headings in row 1 and the data starting in row 2 then the macro
below will place the concatenations in column E starting in Row 2.

Sub Concat()

Dim Table() As Variant
Dim Product() As Variant
Dim State() As Variant
Dim endRow As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim counter As Long

endRow = Cells(Rows.Count, 1).End(xlUp).Row
Table = Range(Cells(2, 1), Cells(endRow, 1)).Value

endRow = Cells(Rows.Count, 2).End(xlUp).Row
Product = Range(Cells(2, 2), Cells(endRow, 2)).Value

endRow = Cells(Rows.Count, 3).End(xlUp).Row
State = Range(Cells(2, 3), Cells(endRow, 3)).Value

counter = 2
For i = 1 To UBound(Table)
For j = 1 To UBound(Product)
For k = 1 To UBound(State)
Cells(counter, 5).Value = Table(i, 1) _
& " " & Product(j, 1) & " " & State(k, 1)
counter = counter + 1
Next k
Next j
Next i

End Sub

Regards
Rowan


"Onrey" wrote:

I have 3 columns of data that I would like to concatenate to end up with
something like this: T1 APPLE AR
T1 ORANGE AR
T1 BANANA AR and so on, then
T2 APPLE AR
T2 ORANGE AR, etc. showing every possibility of these 3
columns:

Table Product State
T1 APPLE AR
T2 ORANGE NY
T3 BANANA FL
T4 GRAPES
T5 TOMATO
T6
T7

Can anyone help me with this?

Thanks! (in advance)

  #3   Report Post  
Onrey
 
Posts: n/a
Default

Excellent!! Worked like a charm! You're awesome!

"Rowan" wrote:

You could use a macro to do this. Assuming your data is in Columns A,B and C
with the headings in row 1 and the data starting in row 2 then the macro
below will place the concatenations in column E starting in Row 2.

Sub Concat()

Dim Table() As Variant
Dim Product() As Variant
Dim State() As Variant
Dim endRow As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim counter As Long

endRow = Cells(Rows.Count, 1).End(xlUp).Row
Table = Range(Cells(2, 1), Cells(endRow, 1)).Value

endRow = Cells(Rows.Count, 2).End(xlUp).Row
Product = Range(Cells(2, 2), Cells(endRow, 2)).Value

endRow = Cells(Rows.Count, 3).End(xlUp).Row
State = Range(Cells(2, 3), Cells(endRow, 3)).Value

counter = 2
For i = 1 To UBound(Table)
For j = 1 To UBound(Product)
For k = 1 To UBound(State)
Cells(counter, 5).Value = Table(i, 1) _
& " " & Product(j, 1) & " " & State(k, 1)
counter = counter + 1
Next k
Next j
Next i

End Sub

Regards
Rowan


"Onrey" wrote:

I have 3 columns of data that I would like to concatenate to end up with
something like this: T1 APPLE AR
T1 ORANGE AR
T1 BANANA AR and so on, then
T2 APPLE AR
T2 ORANGE AR, etc. showing every possibility of these 3
columns:

Table Product State
T1 APPLE AR
T2 ORANGE NY
T3 BANANA FL
T4 GRAPES
T5 TOMATO
T6
T7

Can anyone help me with this?

Thanks! (in advance)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
print excel columns on less pages a_ryan1972 Excel Discussion (Misc queries) 1 February 9th 05 05:41 PM
Filtering Text Data from Multiple columns Brad Excel Worksheet Functions 6 January 1st 05 03:32 PM
Columns in Excel will not allow user to click in them Kim Excel Discussion (Misc queries) 1 December 28th 04 06:37 PM
Counting the Contents of Two Columns Molochi Excel Discussion (Misc queries) 6 December 22nd 04 08:13 PM
repeated transpose from rows to columns with unequal groups kraymond Excel Discussion (Misc queries) 3 December 20th 04 02:39 PM


All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"