TOP

Fusionar celdas sin perder texto

Descripción

Supongamos que tenemos muchas celdas que necesitamos fusionar con texto. El estándar Excel tiene una función similar: "Fusionar y centrar", pero al realizar la fusión, deja solo el texto de la celda más externa. Por tanto, necesitamos utilizar nuestra propia macro para tales fines.


VBA código para la macro

Para ello, abre el editor Visual Basic (Alt+F11), insert VBA module (Insert - Module) y copia allí el texto de esta función:

Sub MergeCell()
    Const sDELIM    As String = " "
    Dim   rCell     As Range
    Dim   sMergeStr As String
    
    If TypeName(Selection) <> "Range" Then Exit Sub
    
    With Selection
        For Each rCell In .Cells
            sMergeStr = sMergeStr & sDELIM & rCell.Text
        Next rCell
        
        Application.DisplayAlerts = False
        .Merge Across:=False
        Application.DisplayAlerts = True
        
        .Item(1).Value = Mid(sMergeStr, 1 + Len(sDELIM))
    End With
End Sub

Guarde y regrese a Excel.

Ahora seleccione las celdas requeridas y ejecute nuestra macro (Alt+F8) (nombre de la macro: "MergeCell").