セルの幅・高さの自動調整(AutoFit メソッド)
AutoFit メソッド
AutoFit メソッドは、指定したセル・セル範囲(Range オブジェクト)の高さまたは幅を自動調整します。
【書式】
Object.AutoFit
引数・戻り値
- object ・・・ 対象となる Range オブジェクトを指定します。
AutoFit メソッド 使用例
サンプルVBAソース
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Sub Sample_AutoFit() 'C列、D列、E列の列幅自動調整 Range("C1:E4").Columns.AutoFit 'A列の列幅自動調整 Range("A1").EntireColumn.AutoFit 'B列、C列の列幅自動調整 Columns("B:C").AutoFit '3行目から7行目までの行の高さを自動調整 Rows("3:7").AutoFit 'シート全体の行の高さを自動調整 Cells.Rows.AutoFit 'シート全体の列幅を自動調整 Cells.Columns.AutoFit 'シート全体の列幅を自動調整 Cells.EntireColumn.AutoFit 'シート全体の行の高さを自動調整 Cells.EntireRow.AutoFit End Sub |
実行結果
サンプルVBAソース実行前
実行後
関連記事
-
-
書式で検索(Find メソッド,FindFormat プロパティ)
書式で検索 書式を条件にセルを検索する場合、まず、その書式条件を CellFor …
-
-
セルのアドレスを確認(Address プロパティ)
Address プロパティ Address プロパティ・AddressLocal …
-
-
A1参照形式、R1C1参照形式の設定・取得(ReferenceStyle プロパティ)
ReferenceStyle プロパティ ReferenceStyle プロパテ …
-
-
セル内の編集を禁止する(EditDirectlyInCell プロパティ)
EditDirectlyInCell プロパティ エクセルでは、セルをダブルクリ …
-
-
セルを削除する(Delete メソッド)
Delete メソッド Delete メソッドで、指定したセル・セル範囲を削除し …
-
-
対象のセル・セル範囲に数式があるかどうか調べる(HasFormula プロパティ)
HasFormula プロパティ HasFormula プロパティは、対象のセル …
-
-
行・列の表示・非表示(Hidden プロパティ)
Hidden プロパティ Hidden プロパティに True を設定することで …
-
-
VBA で、ワークシート関数を使用(WorksheetFunction プロパティ)
VBA で、ワークシと関数を使用 VBA から、ワークシート関数を呼び出す場合、 …
-
-
数式を設定・取得する(Formula プロパティ・FormulaR1C1 プロパティ)
Formula プロパティ(FormulaR1C1 プロパティ) Formula …
-
-
文字列の横位置を取得・設定する(HorizontalAlignment プロパティ)
HorizontalAlignment プロパティ HorizontalAlig …

