- ベストアンサー
xls:CopyFromRecordset罫線描写
cj_moverの回答
#1-4、cjです。#4、お礼欄へのレスです。 余計なことかも知れませんが、、、。 > 数日以内にお返事頂けない場合はそのままベストアンサーとして締め切らせて頂きます。 「よりベターな解決」を導くことを目指しているつもりではありますが、 残念ながら今回は「ベスト」に値することは出来ていない、というのが自己評価で、 「ベストアンサーを決めずに質問を締め切る」ぐらいが、私見としては妥当な気もしています。 回答者としては、「どんな形であれ「解決した」と報せて頂けること」が何よりこの上ないご褒美と考えています。 解決の目途が立ったということでしたらば、それと解る様に質問をCloseするのはマナーとしても大切なことですし、 お礼という意味で評価を頂けるなら、なおさら有難いことです。 (そもそも回答者が判断することではありませんし、どんな結果であってもただ素直に受け止めるだけですが) ただ、締切前に言及されると、なんとなく返事を書き難いですね。ちょっと躊躇ってしまいました。 > 実は......ちょっとダウンしていまして その後お加減は如何ですか?お大事になさってください。 遅れる旨きちんと伝えようという誠実さは私としては好印象なのですが、 コンディションに関わることは、お互い様だったり(相手の方が大変だったり)する場合も多いので、 なるべく触れない方がベターと思います。(これは私の反省でもあります。) エクスキューズしたい時は「今は余裕がないので後ほど」ぐらいで十分かも、です。 また、返事が遅れることを気にする必要もありません。 皆、(こちらも、)事情を抱えている中で、出来る時にしか出来ないです。 以上、老婆心ながら。 本題、 > With Range("B12") > .Resize(.End(xlDown).Row - .Row + 1, .End(xlToRight).Column - .Column + 24).Borders.LineStyle = xlContinuous > End With お求めなのは、上記3行の解説、という理解でいますので、その部分だけについてお応えします。 まず確認しておきますが、これらの記述は、ADODBとは全く無関係、スタンドアローンなExcelのお話です。 とりあえず、解り易さの為(却って読み難いですが)、Withフレーズを外して、1行に書き直すと以下のようになります。 Range("B12").Resize(Range("B12").End(xlDown).Row - Range("B12").Row + 1, Range("B12").End(xlToRight).Column - Range("B12").Column + 24).Borders.LineStyle = xlContinuous 内容としては、 ● 採り込んだデータ範囲に罫線を引く。 ●●1)Range("B12")を基準に、必要な行数、必要な列数でセル範囲を指定する。 ●●● .Resizeプロパティ【書式:Range().Resize(RowSize, ColumnSize)】で、 Range("B12")を(左上のセルとして)基準に、必要な行数、必要な列数でセル範囲の大きさを指定する。 ※.Resizeプロパティ については、VBAのヘルプを引いて確認してください。 ●●●●r)行サイズ指定 Range("B12").End(xlDown).Row で「行方向に連続したデータの最下行」の絶対的な行位置を数値で採り、 Range("B12").Row で、基準となるセルの行位置(この場合は12)を採り、必要な行数を計算する。 例えば、レコード数が10である場合は、 Range("B12").End(xlDown).Row は、21 Range("B12").Row は、12 Range("B12").End(xlDown).Row - Range("B12").Row は 21 - 12 = 9 となるので、 + 1 を加えて、10にする。 といった具合です。 Range("B12").End(xlDown).Row - 11 のように、"B12"を決め打ちにして書いても求まりますが、 With Range("B12") .Resize(.End(xlDown).Row - .Row + 1, ...... End With のようにWithフレーズを用いることで、基準となるRange("B12")を変更する必要が出てきても、 1カ所("B12"を)書換えるだけで(必要な行数指定に)対応できるように書いています。 ※.Endプロパティ については、VBAのヘルプを引いて確認してください。 Range("B12").End(xlDown) のxlDownの意味についてですが、 基準となるセル(Range("B12"))から下方向に、最初に見つかる空セルのひとつ上のセル、を レコードの終端として取得します。 もしも、間に空セル(データベースでいう所のNull)があると、正しく機能しませんが、 1列目(第1フィールド)にNull値、というのは普通はあり得ないでしょうから、この方法を採っています。 一般的なExcelの手法としては、 With Range("B12") .Resize(Cells(Rows.Count, .Column).End(xlUp).Row - .Row + 1, ...... End With とか、 With Range("B12") .Resize(Cells(10001, .Column).End(xlUp).Row - .Row + 1, ...... End With などのように、下から上方向に探して、レコードの終端として取得する方法もあります。 ●●●●c)列サイズ指定 Range("B12").End(xlToRight).Column で「列方向に連続したフィールドの最右列」の絶対的な列位置を数値で採り、 Range("B12").Column で、基準となる列位置(この場合は12)を採り、必要な列数を計算する。 という意図で書かれたものでしたが、この方法では、Null値があると不正な結果になってしまいますね。 フィールド数は固定?という話のようですから、この部分は、直値で指定してあげればいいです。(修正■) ●●2).Borders.LineStyle = xlContinuous で、罫線を引く。 この部分は説明不要と思います。 解説としては以上のようになります。 列数は固定でいい?ようなので、それを踏まえると With Range("B12") .Resize(.End(xlDown).Row - .Row + 1, 24).Borders.LineStyle = xlContinuous End With のように修正■されます。 後は、.Endプロパティ の使い方として、下から上方向に探す必要がある場合などは、 実用上のニーズに照らして応用してみてください。 拙い説明ですが、以上です。
関連する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の定数はどのように宣言すればよいのでしょうか? よろしくお願いいたします
- ベストアンサー
- Visual Basic
- 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
- ベストアンサー
- Windows Vista
- エクセル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
- ベストアンサー
- Visual Basic
- 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
- ベストアンサー
- Visual Basic
- ,最終行から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
- ベストアンサー
- オフィス系ソフト
お礼
落ち着いて読み直し、 各プロパティの細かい文法はまだですが、 それ以外の記述方法については すべて理解できました。 このたびは大変ご親切に、そしてご丁寧に ありがとうございました。
補足
こんにちは。 躊躇わせてしまう結果になりすみません。 はい、もう解決することができましたので マナーとして近日中に締め切る予定です。 さらに、迅速な回答を頂き、さらに質問する際のお作法も ご教示いただき、大変満足していますので、 ベストアンサーは送らせて頂きます! ご了承ください。 その上で、最後に追加の質問をさせて頂いているため 質問したまま締め切る形になるとそれも失礼かと思い 断らせて頂きました。 なんにせよ、答えづらい展開になってしまったようで ごめんなさい。 コンディションの件、はい、復調してきました。 ありがとうございます。 言及しない方がよい旨、理解しました。 そうですね、返事が遅れますくらいにしておきます。 まずは本題前の部分について、返信させて頂きました。 ありがとうございました。 本題の理解はじっくり読み込ませて頂き、 そののちにお礼欄にてご連絡させて頂きます。