VBAで行の高さや列の幅を取得・変更する方法です。前提となる行・列の取得についてはRows、Columnsの記事で解説しています。
行の高さを取得
行の高さを取得
Rows(またはRange).Height
Rows(またはRange).RowHeight
※取得される値はポイント単位
Rows(またはRange).Height
Rows(またはRange).RowHeight
※取得される値はポイント単位

まずは行の高さの取得ですが、行かセルを指定してHeightプロパティかRowHeightプロパティを付ければ取得できます。
たとえばMsgBox Rows(1).Heightとすることで、一行目の高さを取得して表示できます。
たとえばMsgBox Rows(1).Heightとすることで、一行目の高さを取得して表示できます。

MsgBox Rows(1).RowHeightとしても同様に行の高さを取得できます。

Range(
"
A1"
).HeightまたはRange("
A1"
).RowHeightでもオッケイです。HeightとRowHeightは、単一行の高さを取得であればどっち使っても同じ結果になります。
HeightとRowHeightのちがい
①Heightは読み取り専用ですが、RowHeightは書き込みにも使えます(後述)。
②Heightは範囲の高さをまとめて取得することができます。
(RowHeightで複数行の高さを取得すると、全て同じ高さの場合一行分の高さを返し、行によって高さが違う場合Nullを返す)
範囲行の高さの取得

範囲の高さを取得するには、Rows(
Range(
"
1:3"
).Heightのようにして範囲行を指定します。Range(
"
A1:A3"
).Heightでも同じ結果になります。
。
横幅は関係ないので、Range(
"
A1:A3"
).HeightでもRange("
A1:C3"
).Heightでも結果は同じです。
高さが範囲内で不均一でも取得できます。
列幅を取得
列幅を取得
Columns(またはRange).ColumnWidth
※取得される値は文字数単位
Columns(またはRange).ColumnWidth
※取得される値は文字数単位
Columns(またはRange).Width
※取得される値はポイント単位

列幅も同様に、一列目ならColumns(1).ColumnWidthで取得できます。

Range(
"
A1"
).ColumnWidthでも同じ意味になります。この8.38は標準フォントの1文字換算で何文字分かを意味し、通常操作で幅を規定する場合もこの単位が使用されます。
Columns(1).WidthもしくはRange(
"
A1"
).Widthの場合、ポイント単位で列幅を取得できます。なお、Widthも読み取り専用のプロパティです。WidthとColumnWidthのちがい
繰り返しになりますが、まとめるとこうなります。
①Widthは読み取り専用ですが、ColumnWidthは書き込みにも使えます(後述)。
②Widthは範囲の幅をまとめて取得することができます。
(ColumnWidthで範囲の列幅を取得すると、全て同じ列幅の場合一列分の幅を返し、列によって幅が違う場合Nullを返す)
③Widthではポイント単位、ColumnWidthでは標準フォントの文字数単位で幅が取得されます。
範囲列の幅の取得

範囲列の幅を取得するには、Columns(“A:C”).Widthのようにするか、

またはRange(“A1:C1”).WidthのようにRangeから指定します。単位はポイント単位となります。
行の高さの変更

行の高さを変更するには、Rows(1).RowHeight = 20のようにして、取得したプロパティに値を代入します。単位はポイントです。

実行結果です。Range(
"
A1"
).RowHeight = 20でも同じ結果になります。
Heightは読み取り専用のプロパティなので使えません。
行の高さをまとめて変更

範囲の行の高さを変更する場合は、Rows(
"
1:3"
).RowHeight = 30のように書くか、
またはRange(
"
A1:C3"
).RowHeight = 25のようにしても可能です。標準の高さにする

行を標準の高さにしたい場合は、UseStandardHeightプロパティをTrueにします。

Rows、RangeどっちでもOKで、範囲指定も可能です(Range(
"
A1:C3"
).UseStandardHeight = True)。行数に合わせて自動調整

Rowsに対してAutofitメソッドをくっつけることで、入力された行数に合わせて行の高さを自動調整することができます(Rows(
"
1:3"
).AutoFit)。列幅の変更

列幅も行の高さ同様に、Columns(1).ColumnWidth = 20などで変更可能です。

実行結果です。ポイント単位ではなく、文字数単位で幅は指定されます。
Range(
Range(
"
A1"
).ColumnWidth = 20でも同じ結果になります。
Widthは読み取り専用のプロパティなので使えません。
列幅をまとめて変更

列幅をまとめて変更する場合、Columnsの後に列番号をアルファベットでつけてColumns(
"
A:C"
).ColumnWidth = 20のようにするか、
またはRange(
"
A1:C3"
).ColumnWidth = 25のようにしてもOKです。標準の幅にする

列幅を標準の幅にしたい場合は、UseStandardWidthプロパティをTrueにします。

Columns、RangeどっちでもOKで、範囲指定も可能です(Range(
"
A1:C3"
).UseStandardWidth = True)。文字数に合わせて自動調整

Columnsに対してAutofitメソッドをくっつけることで、入力された文字数に合わせて列幅を自動調整することができます(columns(
"
A:C"
).AutoFit)。他のシートの行の高さ・列幅を取得/変更
' vba
' 一番左のシートの1列目の幅を表示
MsgBox Worksheets(1).Columns(1).Width
他のシートに対して行の高さ・列幅関連の操作を行いたい場合、頭にWorksheetsないしはSheetsを付けて、シートを指定してやればOKです。
' vba
' Sheet1の1行目の高さを20ポイントに変更
Sheets("Sheet1").Rows(1).RowHeight = 20
シートはインデクス番号でも指定できます。
関連記事
通常操作で列幅・行の高さを変更する方法です。単位の変更方法についても言及しています。
列幅と行の高さを一致させ、範囲やシートを方眼紙状にする方法です。

Excel(エクセル):行、列
Excelの行、列関係操作、関数、VBAです。他のまとめとかぶる部分が多い場合はリンク貼ります。
行・列の選択
行・列の選択方法です。
テーブル内の行・列一括選択方法です。
VBA(マクロ)で列・...

関数・演算子・メソッド・プロパティ名から探すExcel/VBA(マクロ)使い方・組み合わせ方まとめ
こちらはExcelやメソッドの諸機能を、機能の名称から探せるまとめ記事です。

やりたいことから方法を探すエクセル(Excel)操作・関数・VBA(マクロ)逆引きまとめ
逆引き(やりたいことから探す)Excel記事まとめ
コメント