'Macros for Horizontal and Vertical concatenation
'Copyright, Andrés Gonzalez, 2008
Sub mezclar() 'horizontal concatenation
For Each fila In Selection.Rows
mensaje = ""
For Each celda In fila.Cells
mensaje = mensaje & celda.Value & " "
Next
fila.Clear
fila.Cells(1, 1).Value = mensaje
Next
End Sub
Sub mezclarV() 'vertical concatenation
For Each columna In Selection.Columns
mensaje = ""
For Each celda In columna.Cells
mensaje = mensaje & "- " & celda.Value & Chr(10)
Next
columna.Clear
columna.Cells(1, 1).Value = mensaje
Next
End Sub
Let's say you have the following table:
Albert | Einstein |
Nikola | Tesla |
With the first macro the result will be:
albert einstein |
nikola tesla |
And with the second, it will be:
- albert | - einstein |
I think this one is cool, isn't it?
No comments:
Post a Comment