14
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excelで、行の高さを自動でいい感じにする

Last updated at Posted at 2016-02-16

Excelの行高さの自動調整についてです。

Excelシートの一番左の行番号のところをダブルクリックすると
その行の高さを自動で調整してくれますが、

大体の場合「ギュッと縦に詰まりすぎ」になります。
見づらいです。

そこで、「自動調整+余白の高さ」に自動調整するマクロを書きました。
ショートカットに登録すると快適です。

Sub NiceRowheight()
'余白設定
Const buf = 10
Application.ScreenUpdating = False
'とりあえず選択範囲の行高さをAutoFitする
Selection.Rows.AutoFit

'選択範囲が広すぎる時のために、データ最終行を獲得しておく
maxrow = Range("A1").SpecialCells(xlLastCell).Row

'その後、微妙に行高さを広げる。(1列目のみ処理)
For Each hoge In Selection.Columns(1).Cells
    hoge.RowHeight = hoge.RowHeight + buf
    
    '経過観察&終了判定
    i = i + 1
    If i Mod 2000 = 0 Then
        '終了判定(データの最終行を越えてたら終了する。)
        If hoge.Row > maxrow Then Exit For
        Application.StatusBar = i
        DoEvents
    End If
Next

Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
14
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?