Upravte výšku řádku sloučených buněk pomocí VBA v aplikaci Microsoft Excel

Anonim

Otázka:
Sloučené buňky nemají po zalomení řádku správnou výšku. Jak to mohu opravit?

Odpovědět:
Vložte následující kód do standardního modulu.

 Sub AutoFitMergedCellRowHeight () Dim CurrentRowHeight jako Single, MergedCellRgWidth jako Single Dim CurrCell jako rozsah Dim ActiveCellWidth jako Single, PossNewRowHeight jako Single If ActiveCell.MergeCells Then With ActiveCell.MergeArea If .Rows.Count = 1 And. Falešný CurrentRowHeight = .RowHeight ActiveCellWidth = ActiveCell.ColumnWidth pro každý výběr CurrCell MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth Next .MergeCells = False .Cells (1) .ColumnWidth = Merged ColumnWidth = ActiveCellWidth .MergeCells = True .RowHeight = IIf (CurrentRowHeight> PossNewRowHeight, _ CurrentRowHeight, PossNewRowHeight) End If End With End If Application.ScreenUpdating = True End Sub