Devo adattare le celle che seleziono di volta in volta ( celle unite ) al contenuto.
Ho trovato questa macro ma funziona soltanto una cella alla volta.
Ho cercato di capire cosa cambiare per utilizzarla su una selezione di celle ma non ci sono riuscito. Ho provato cambiando As Single con As Range e altre cose che ho trovato facendo una ricerca ma non funziona.
Il testo della macro è questo :
Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
Range(Selection, Range("A1:B65536").End(xlDown)).Select
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
.WrapText = True 'crea un invio automatico (modifica fs)
If .Rows.Count = 1 Then 'And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Sub
Grazie