Reguleerige ühendatud lahtrite rea kõrgust, kasutades Microsoft Excelis VBA -d

Anonim

Küsimus:
Ühendatud lahtritel pole pärast reavahetust õiget kõrgust. Kuidas seda parandada?

Vastus:
Sisestage standardmoodulisse järgmine kood.

 Sub AutoFitMergedCellRowHeight () Dim CurrentRowHeight as Single, MergedCellRgWidth As Single Dim CurrCell As Range Dim ActiveCellWidth as Single, PossNewRowHeight as Single Kui ActiveCell.MergeCells Siis ActiveCell.MergeArea Kui .Rows.Counting = 1Ut. False CurrentRowHeight = .RowHeight ActiveCellWidth = ActiveCell.ColumnWidth iga valiku CurrCelli jaoks MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth Järgmine .MergeCells = False .Cells (1) .ColumnWidth = MergedCellReHowRightWidth. ColumnWidth = ActiveCellWidth .MergeCells = True .RowHeight = IIf (CurrentRowHeight> PossNewRowHeight, _ CurrentRowHeight, PossNewRowHeight) End If End with End if Application.ScreenUpdating = True End Sub