I need to take this code:
Sub ConcatColumns()
Do While ActiveCell <> ""
ActiveCell.Offset(0, 1).FormulaR1C1 = _
ActiveCell.Offset(0, -1) & " " & ActiveCell.Offset(0, 0)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
And I need to modify it so it will not only join two columns but up to 4, with the possibility of being able to choose which columns I want to concatenate. I also need the joined text to be separated by a comma and since this is Excel, I'm wondering if there's a way I can add some formatting if one of the columns is a date?
For example, manually I have to use this formula to make sure my dates are formatted as mm/dd/yyyy when using TEXTJOIN:
=TEXTJOIN(",",TRUE,IF(I4="","",(TEXT(I4,"mm/dd/yyyy"))),IF(J4="","",(TEXT(J4,"mm/dd/yyyy"))),IF(K4="","",(TEXT(K4,"mm/dd/yyyy"))))
This is how my data looks:
This can go on with up to 5-10 other sets of ID's with their dates.
This is the result I need and what I'm having to do now do with =TEXTJOIN:
As you can see the dates don't come over formatted, even when I try to do it with the dropdown so I have to add some =TEXT formatting with the formula I pasted above.
Thanks in advance!
Here's one approach. It will concatenate selection cell contents in the order the cells/ranges were selected (luckily Excel keeps track of this when you make a multi-area selection). Result goes in the last-selected cell.
Example: cells on row 3 were selected in the order shown while holding down Ctrl key. Make sure to select an empty cell last as the destination for the result.
Note: the macro will step down through the rows below as long as they have content, so only select cells on the first row of the data you want to work on.
Result: