書式で全体に罫線を引いたり行の高さを変え、ページ設定でヘッダーフッターや余白等を設定するをマクロに登録しようと思います。
社内システムから引き出したデータの為、データ範囲はA1から始まって終わりのセルはその時々によって違います(データの入っている最終セル)
この場合のVBAの編集方法を教えてください。
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
xlDown が 空白のひとつ手前の行
xlToRightは 空白の左となりの列となります。
最初にA1を選択してから 空白までの行、列を 選択して
その時点での
ActiveCell.Row
ActiveCell.Column
を用いて処理したらいいです。
それぞれ選択中の行と列を取得できます。
エクセルの「ツール」→「マクロ」→「新しいマクロの記録」
で自動的にマクロを作った法は一番効率的なと思います。
サンプル、ご参考まで:
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Rows("1:26").Select
Selection.RowHeight = 13
素晴らしいヽ(^。^)ノ
やりたい事出来ました。
ありがとうございました。
早速の回答をありがとうございます。
早速やってみましたが、最終セルIV65536に罫線がひかれ、デバックエラーになってしまいました。