• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:xls:CopyFromRecordset罫線描写)

xls:CopyFromRecordset罫線描写

cj_moverの回答

  • cj_mover
  • ベストアンサー率76% (292/381)
回答No.6

#1-5、cjです。#4補足欄へのレスです。 > すみません、一つだけうまくいかないケースがありました。 > 出力するレコードが1レコードだけのときです。 > その場合だけは、エクセル内の一番下の行まで全部 > 罫線が引かれてしまいました。 > 原因おわかりになりますでしょうか。 "レコードが1レコードだけのとき”への対策としては、 #5で示した.End(xlDown)を応用して、下から上へ探すように応用しておけばいいです。   With Range("B12")     .Resize(Cells(Rows.Count, .Column).End(xlUp).Row - .Row + 1, 24).Borders.LineStyle = xlContinuous   End With とか、   With Range("B12")     .Resize(Cells(10001, .Column).End(xlUp).Row - .Row + 1, 24).Borders.LineStyle = xlContinuous   End With とかになります。 レコード最下行の取得方法についてどちらを選ぶか、は、そちらのExcelシートのレイアウト次第ですが、 Excelに用意された最下行(65536または1048576)から上に探すか、 10001行めから上に探すか、の違いです。

ARIES10
質問者

お礼

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

ARIES10
質問者

補足

ちなみに、出力がゼロの場合、 つまり検索対象のレコードがなかった場合に この罫線を引く部分でエラーになりましたので カウンタをつけて、カウンタがゼロ以上のときのみ このwithプロパティを機能させるようにしました。 特別お知らせする内容でもないですが、一応。

関連するQ&A

  • Excel VBAの罫線描画マクロをOpenOfficeCulcで実行。罫線が描画されない。

    Excel VBAで作成したマクロをOpenOffice.orgのCulcに単純移行して 実行してみたのですが、コードは実行されるのに罫線が描画されない 現象が発生しています。 罫線描画はCulcとExcelで互換が遅れている部分だと聞いていますが、 Culc独自のマクロで作成するしか回避方法はないのでしょうか? マクロは下記のような構成になっています。 REM ***** BASIC ***** Option VBASupport 1 Sub draw_line() With Worksheets("drawline") .Range("B2:E8").Borders(xlEdgeLeft).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeTop).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeBottom).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeRight).LineStyle = xlContinuous .Range("B2:E8").Borders(xlInsideVertical).LineStyle = xlContinuous .Range("B2:E8").Borders(xlInsideHorizontal).LineStyle = xlContinuous End With End Sub

  • .NET上でエクセル上に罫線を引く

    VB.NETを独学で勉強しているものです .NETのプログラミングでEXCELを開いてセルに数値を入力するところまではできるようになったのですが、罫線を引こうとするとうまくいきません。 ws.Range(Karist).Borders.LineStyle = xlContinuous のところの「xlContinuous」の下部に波線が出て、変数が宣言されていないと出るのですが、EXCELの定数はどのように宣言すればよいのでしょうか? よろしくお願いいたします

  • VBA罫線

    VBA罫線 a = 9 With Range(Cells(3, 2), Cells(a, 5)) .Borders(xlEdgeTop).LineStyle = xlContinuous .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlInsideVertical).LineStyle = xlContinuous .Borders(xlInsideHorizontal).LineStyle = xlContinuous End With どこのワークシートかを指定する場合はどうしたらいいのでしょうか?

  • エクセルVBAにおける罫線の色指定について

    エクセルVBAの初心者です。 使用機種はWindows VistaでExcel2007です。 後に示すコードではどうして("B4:H7")までの下罫線と ("C4:H8")までの左罫線が青色にならず、黒色のまま になるのでしょうか?("B4:H7")、("C4:H8")ともに 罫線の色は青色にしたいと思っています。 原因と対処方法をご存知の方ご教示願います。 画像も添付しておりますので、合わせてご参照ください。 Sub 日程表作成() Set WS1 = Worksheets("sheeT1") With WS1 .Range("B3") = "日" .Range("B3").Select End With Selection.AutoFill Destination:=Range("B3:H3") WS1.Range("B3:H3").Select With Selection.Borders(xlLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With '下線を二重線に変える Range("B3:H3").Select Selection.Borders(xlBottom).LineStyle = xlDouble WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous WS1.Range("B3:H8").RowHeight = 35 '日程表の中に横線を入れる WS1.Range("B4:H7").Select Selection.Borders(xlBottom).LineStyle = xlContinuous WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous '日程表の中に縦線を入れる WS1.Range("C4:H8").Select Selection.Borders(xlLeft).LineStyle = xlContinuous WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous '曜日のセルを塗りつぶす With WS1 .Range("B3:B8").Interior.ColorIndex = 38 .Range("C3:G8").Interior.ColorIndex = 19 .Range("H3:H8").Interior.ColorIndex = 19 .Range("B4").Activate End With End Sub

  • エクセルVBA 行列の数を指定して罫線を引くマクロ教えてください

    下のようにSheet1に罫線を引く「開始セル(左右端)」「行」「列」が書いてあります。 この条件で罫線をSheet2に引くようにしたいのですが、変数の設定の仕方などが分かっていないようで、できません。教えていただけないでしょうか。マクロの記録をとったところ、下のようになりました。よろしくお願いします。 開始セル Sheet2!A1・・・Sheet1のB1セル 行 8・・・Sheet1のB2セル 列 2・・・Sheet1のB3セル Sub borders() Range("A1:B8").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 End Sub

  • データーに合わせて罫線を引く

    よろしくお願いします。 セル(H6)を起点にデーターのある部分に罫線を引きたいのですが 計算式(関数)が、入っているセルにも罫線が引かれます。 計算式(関数)は入っているが、データーが入っていない場合は罫線を引かない 方法を教えてください。 現況の記述です。 Sub 罫線() With Range("H6").CurrentRegion.Borders .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic With .Item(xlInsideHorizontal) .LineStyle = xlDash .Weight = xlHairline .ColorIndex = xlAutomatic End With With .Item(xlInsideVertical) .LineStyle = xlDash .Weight = xlHairline .ColorIndex = xlAutomatic End With End With End Sub

  • エクセルでデータがある部分だけ罫線で囲いたいです。

    エクセルでデータがある部分だけ罫線で囲いたいです。 エクセルのファイルを開いて、データのある部分だけを罫線で囲みたいです。 データーは常に列数も行数も違います。 マクロの記録で行ったら、以下のようになりました。 もう少し短い文章ではできないでしょうか? Sub Macro1() ' ' Macro1 Macro ' マクロ記録日 : 2010/9/22 ' 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 End Sub

  • 表に罫線を最終列まで引きたい

    windows7 とExcel2007でマクロ作成中の初心者です。 最初に、D2:E34を選んで罫線をひき、列を2列移動して、また罫線を引きます。 これをデータのある最終列まで繰り返したいのですが、うまくいきません。 どうしたらよろしいでしょうか。 Sub 勤怠に罫線() Dim n As Integer For n = 1 To 5 勤怠に罫線 Selection.Offset(0, 2).Select 勤怠に罫線 Next n End Sub 以下はマクロの自動記録でコードを書きました。 Sub 勤怠に罫線() Range("D2:E34").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone Range("D2:E34").Select End Sub

  • AccessVBAでExcelを起動し、罫線を引きたいのですが、Exc

    AccessVBAでExcelを起動し、罫線を引きたいのですが、ExcelVBAの罫線を引く関数をAccessVBAで記述するとエラーになります。どういう記述をすればよいのでしょうか? (例)   以下の様にすると、例えば「xlNone」は宣言されていない等のエラーになります。   (ちなみに、Excelの起動と値の入力はできています) Range("A4:C6").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With

  • ,最終行からA1の間に罫線を引く方法は?

    お願いします。 罫線を引くマクロを書きました。(下記) 範囲のJ26は最終行です。この表のデータ量は変化します。 最終行がJ26とは限りません。Z5000かもしれません。 その範囲に罫線をひくのですが、マクロ的に最終行を認知してA1 まで罫線を引くマクロをどう記述すればよいのか教えてください。 Sheets("読み込み").Select Range("A1:J26").Select Range("J26").Activate 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 Range("J3").Select End Sub