【エクセル2003 マクロ】に詳しい方、教えてください。


書式で全体に罫線を引いたり行の高さを変え、ページ設定でヘッダーフッターや余白等を設定するをマクロに登録しようと思います。
社内システムから引き出したデータの為、データ範囲はA1から始まって終わりのセルはその時々によって違います(データの入っている最終セル)
この場合のVBAの編集方法を教えてください。

回答の条件
  • 1人2回まで
  • 登録:
  • 終了:2007/09/22 08:19:27
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

回答2件)

id:taknt No.1

回答回数13539ベストアンサー獲得回数1198

ポイント100pt

Range("A1").Select

Selection.End(xlDown).Select

Selection.End(xlToRight).Select

xlDown が 空白のひとつ手前の行

xlToRightは 空白の左となりの列となります。

最初にA1を選択してから 空白までの行、列を 選択して

その時点での

ActiveCell.Row

ActiveCell.Column

を用いて処理したらいいです。

それぞれ選択中の行と列を取得できます。

id:mokachan

早速の回答をありがとうございます。

早速やってみましたが、最終セルIV65536に罫線がひかれ、デバックエラーになってしまいました。

2007/09/22 00:23:52
id:interview No.2

回答回数29ベストアンサー獲得回数0

ポイント100pt

エクセルの「ツール」→「マクロ」→「新しいマクロの記録」

で自動的にマクロを作った法は一番効率的なと思います。

サンプル、ご参考まで:

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

id:mokachan

素晴らしいヽ(^。^)ノ

やりたい事出来ました。

ありがとうございました。

2007/09/22 08:18:17

コメントはまだありません

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません