Supponiamo di avere molte celle che dobbiamo unire insieme al testo. Il set standard Excel ha una funzione simile: "Unisci e centra", ma quando esegue l'unione lascia solo il testo della cella più esterna. Quindi dobbiamo utilizzare la nostra macro per tali scopi.
Per fare ciò, apri l'editor Visual Basic (Alt+F11), inserisci il modulo VBA (Insert - Module) e copia lì il testo di questa procedura:
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
Salva e torna a Excel.
Ora seleziona le celle richieste ed esegui la nostra macro (Alt+F8) (nome macro: "MergeCell").