View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Merging two columns and keeping the data from both

Stosh wrote...
There is one crucial feature to the 2007 Excel that has been overlooked.
Throughout all versions of Excel there has always been the feature of
converting text to table, however there is no way to do this in reverse.

....

Presumably you mean Data Text to Columns when you write converting
text to table. It was added in Excel 97.

As for the reverse, use formulas. If you wanted to merge cols A and B,
in another range write the formulas =A1&whatever_delimiter&B1, fill
down (easier when the formulas would be in col C adjacent to cols A and
B), paste special as values into col A, clear the formulas, and merge
cols A and B (or just clear col B).

If you really have to have this, it's not that complicated a macro.
[All lines begin with at least 2 spaces. Any that don't have wrapped
from the end of the previous line and should be reconnected.]

'-- begin VBA ------
Sub foo()
Const TTL As String = "Merge Table"
Static s As String
Dim i As Long, j As Long, k As Long, t As String

If Not TypeOf Selection Is Range Then
MsgBox Prompt:="No range selected.", Title:=TTL,
Buttons:=vbOKOnly
Exit Sub
End If

s = InputBox(Prompt:="Enter delimiter.", Title:=TTL, Default:=s)

For i = 1 To Selection.Areas.Count
For j = 1 To Selection.Areas(i).Rows.Count
t = ""
For k = 1 To Selection.Areas(i).Columns.Count
t = t & s & Selection.Areas(i).Cells(j, k).Text
Selection.Areas(i).Cells(j, k).ClearContents
Next k
Selection.Areas(i).Cells(j, 1).Value = Mid(t, Len(s) + 1)
Next j
Next i

End Sub
'-- end VBA ------

If even 0.01% of Excel users each were allowed to add just one
must-have feature, Excel would become completely unwieldy.