Excelの範囲指定方法とは?

このQ&Aのポイント
  • Excelの範囲指定方法について教えてください。
  • 具体的な質問として、表の範囲指定方法について知りたいです。
  • 特に、列の最後の取り方がわからないです。
回答を見る
  • ベストアンサー

空白前の1つ左のセルに合わせる

セル範囲を設定したいのですがどうすればいいのか教えてください。    C   D   E   F   G   H I 17    品目  4月  5月  6月 7月  結果 18 No.1 りんご  200 50 23 52  325      19 No.1 もも 20 1 53 1   75 20 No.1 いちご 23 3   26 21 No.1 なし 1 52     53 22 No.1 バナナ 5 2 7 23 結果      226 126 76 58   486  上記のような表があります。 C18からH列の7月の最後の結果表までの範囲 C18:H23 を範囲指定をしたいのです。 しかし行も増える事があり、列も8月・9月と増えて行きます。 途中まではマクロを作成できたのですが、 列の最後の取り方がわかりません。 できれば「結果」という文字の手前での列で 最終行までの範囲を取るにはどうすればいいですか? Range("$C$18" & Range("C65536").End(xlUp).Row).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Copy

質問者が選んだベストアンサー

  • ベストアンサー
  • Masa2072
  • ベストアンサー率51% (94/182)
回答No.1

Range("C18", Cells(Range("C18").End(xlDown).Row, Range("D17").End(xlToRight).Column - 1)).Select というのはどうでしょうか?

kuro1019
質問者

お礼

Masa2072様 できました。ありがとうございました。 知らない言葉が増あったので調べてちゃんと理解したいと思います。 ありがとうございました。

関連するQ&A

  • このマクロを高速化させるにはどうすればいいですか?

    VBA初心者で、とりあえず頑張って作ってみました。以下のVBAでの修正点を教えてください。 (英単語の小テスト用につくりました。) Range("C3:E22,H3:J22").Select Selection.Font.ColorIndex = 2 Selection.Interior.ColorIndex = 2 Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone Selection.Borders(xlEdgeBottom).LineStyle = xlNone Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone ' ここまでは、共通の動作 Range("A1").Select ActiveCell.FormulaR1C1 = "20" ' 問題数に応じて、数字を変更 Range("C3:E22,H3:J22").Select 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("D3:E22,I3:J22").Select Selection.Font.ColorIndex = 1 ' 文字を黒くする Range("C3:C22,H3:H22").Select Selection.Interior.ColorIndex = 16 ' セルをグレーにする Rows("3:18").Select Selection.RowHeight = 31.5 ' セルの幅を指定 ActiveSheet.PageSetup.PrintArea = "$B$1:$K$25" ' 印刷範囲を指定 Range("U3:U42").Select Selection.ClearContents ' 四線を消去 Range("D3:D4").Select Calculate ' 再計算完了 宜しくお願いします。 また、このVBAは慣れている人から見ると何点くらいですか?(感覚で結構です)

  • VBAで「一度で全ての罫線をなくす」コードを書くときは

    With Selection .Borders(xlDiagonalDown).LineStyle = xlNone .Borders(xlDiagonalUp).LineStyle = xlNone .Borders(xlEdgeLeft).LineStyle = xlNone .Borders(xlEdgeTop).LineStyle = xlNone .Borders(xlEdgeBottom).LineStyle = xlNone .Borders(xlEdgeRight).LineStyle = xlNone .Borders(xlInsideVertical).LineStyle = xlNone .Borders(xlInsideHorizontal).LineStyle = xlNone End With これしかないですか? 「一度で全ての罫線をなくす」 みたいなのがあったら教えてください。よろしくお願いします。

  • 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

  • Excell2007 のVBAでのこと

    罫線を引くとき、マクロの記録をとった時 次のような記述が記録されました。 (VBA・マクロの勉強中です) Range("B6:G21").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlDouble .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThick End With この中の .TintAndShade = 0 はどのような働きをするのでしょうか? (何を指定する命令なのでしょうか?) ちなみにエクセル2003ではこの記述はなかったように思うのですが。 初心者ですので分かり易くお願いいします。 どうかよろしく・・・

  • Excel2003枠を作るマクロ

    右側に空白の行を一つつくって枠を作りたいです。 たとえば、G100が一番右下とするとH100まで枠を作りたいのですが、きれいにかくにはどうしたらよいでしょうか? マクロ記録でやると、下のようになるのですが右下が100で有るとは限らないのでその行を定義する必要があると思うのですが、そのあたりがさっぱりわかりません。 よろしくお願いいたします。 Sub Macro1() Selection.End(xlDown).Select Range("H100").Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlToLeft)).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

  • エクセル2000 VBA

    マクロの記録で記述されたコード余分を誤って削除してしまい、     修正方法がわかりません。 どなたかお解りになりますか。 ActiveWindow.SmallScroll ToRight:=-5 ActiveWindow.ScrollColumn = 3 Range("B27:C44").Copy ActiveWindow.SmallScroll ToRight:=4 Range("N27").Paste ←ここでエラーになります! Application.CutCopyMode = False Range("O27:O44").ClearContents Range("N27:O44").Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone

  • ,最終行から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

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

    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

  • 削除のマクロ(エクセル)

    Sub test()  Selection.Delete  Selection.Interior.ColorIndex = xlNone  Selection.Borders(xlDiagonalDown).LineStyle = xlNone  Selection.Borders(xlDiagonalUp).LineStyle = xlNone  Selection.Borders(xlEdgeLeft).LineStyle = xlNone  Selection.Borders(xlEdgeTop).LineStyle = xlNone  Selection.Borders(xlEdgeBottom).LineStyle = xlNone  Selection.Borders(xlEdgeRight).LineStyle = xlNone  Selection.Borders(xlInsideVertical).LineStyle = xlNone  Selection.Borders(xlInsideHorizontal).LineStyle = xlNone  Selection.ClearContents End Sub 上記マクロは、まず図形が選択状態にある時はそれを削除します。 また、セルが選択状態にある時は、選択範囲内の文字を消し、罫線を消し、塗りつぶしの色を消します。 上記マクロを実行すると不具合が生じます。 選択範囲外のデータが消えたり、選択範囲外のセルが移動したりしてしまいます。    c5 d5 e5 f5    c6 d6 e6 f6    c7 d7 e7 f7    c8 d8 e8 f8 上記の全てのセルにデータが入力されている場合、d6:e7を選択してマクロを実行すると、d6:e8のデータが消えてしまいます。 d6:d7を選択してマクロを実行すると、d6:e7のデータが消える上にf6:f7が一セル分左に移動してしまいます。 マクロ内の"Selection.Delete"をコメントにして実行すると不具合は生じることなく、選択範囲内のデータだけに作用させることができます。 ただ、"Selection.Delete"を外すと、「図形が選択されている時は図形を削除する」ができなくなります。 どのようにマクロを修正すれば、セルのデータと図形のそれぞれを不具合なく削除させることができるでしょうか?

  • エクセル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