Skip to content

Instantly share code, notes, and snippets.

@mjdescy
Created April 9, 2020 00:20
Show Gist options
  • Save mjdescy/53fc4f3a9bfc694c55dfb99684fcbc50 to your computer and use it in GitHub Desktop.
Save mjdescy/53fc4f3a9bfc694c55dfb99684fcbc50 to your computer and use it in GitHub Desktop.
Adjust Row Height in Excel
Option Explicit
Const DefaultRowHeight As Double = 14.5
Public Sub IncreaseRowHeightByOneLine()
Call SafelyAdjustRowHeightForAllRowsInRange(Range:=Selection, RowHeightAdjustment:=DefaultRowHeight)
End Sub
Public Sub DecreaseRowHeightByOneLine()
Call SafelyAdjustRowHeightForAllRowsInRange(Range:=Selection, RowHeightAdjustment:=-DefaultRowHeight)
End Sub
Private Sub SafelyAdjustRowHeightForAllRowsInRange(ByRef Range As Excel.Range, ByVal RowHeightAdjustment As Double)
Dim Row As Excel.Range
For Each Row In Range.Rows
Call SafelyAdjustRowHeight(Range:=Row, RowHeightAdjustment:=RowHeightAdjustment)
Next Row
End Sub
Private Sub SafelyAdjustRowHeight(ByRef Range As Excel.Range, ByVal RowHeightAdjustment As Double)
Dim NewRowHeight As Double
NewRowHeight = Range.RowHeight + RowHeightAdjustment
If NewRowHeight <= 0 Then
Exit Sub
End If
Range.RowHeight = NewRowHeight
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment