• ベストアンサー

Cells.ColorIndex

セル全体の色を取りたいのですが Cells.ColorIndex = xlAutomatic だと実行時エラー438になるのですが、 なぜでしょうか?

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

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

こんにちは。 Cells.Interior.ColorIndex = xlColorIndexAutomatic または Cells.Font.ColorIndex = xlColorIndexAutomatic ということなのでは? Range オブジェクトには.Color プロパティというのはありませんから エラーになります。 xlColorIndexAutomatic は xlAutomatic でも値は一緒ですし、マクロの記録などではxlAutomatic になるかも知れませんが、正式にはxlColorIndexAutomatic ということだけです。必要以上に気にすることはありません。 以上です。

qqeguqxcjzz
質問者

お礼

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

その他の回答 (1)

回答No.2

色を取るという意味がわかりませんが、 セルの着色を消すということなら、 Cells.Interior.ColorIndex = 0 です。

qqeguqxcjzz
質問者

お礼

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

関連するQ&A

  • 「Cells(1, 1).Interior.ColorIndex = 255」がエラーになる理由

    Cells(1, 1).Interior.ColorIndex = 255 を実行するとエラーになります。 「InteriorクラスのColorIndexプロパティを設定できません。」 となります。 しかし Cells(1, 1).Interior.ColorIndex = 34 はエラーにならず水色になります。 赤は255ではないのですか? 何が原因なのかわかりません。 よろしくお願いします。

  • Excel VBA 選択した範囲の1行目に色を付けたい

    VBA初心者です。 セルB4~F15に表が作成されています。 プロシージャを実行して、セルB5~F15にブルー。表1行目のセルB4とF4のみに赤の色を付けるというコードを記述したいのです。 以下のように記述しました。 Sub セルに色()    Range("B4").Select    ActiveCell.CurrentRegion.Select    Selection.Interior.ColorIndex = 8    Selection.Range(Cells(1, 1),Cells(1,5)).Interior.ColorIndex = 3 End Sub Rangeでは連続シートになるため、Unionに変更してみましたが、 Unionはオブジェクトがサポートされていない旨のエラーが出ました。 どのように記述すればよいでしょうか? どうぞよろしくお願いいたします。

  • マクロCellsがわからなくて困っています

    マクロのCellsについて、夜も眠れないほど悩んでいます。 助けてください。 相談は以下です。 Cells(1,1).Select の行、列部分に、他のセルに入力済みの数値を指定したり、算出することはできますか? たとえば、あらかじめセルに数値が入っていたら Cells(1,A1).Select Cells(1,B1-A1).Select のように。(誤った文章ですが・・・) またこの方法に使えるCells以外の言葉があれば、教えてくださいませ!

  • EXCELで4色の色をつけるVBA(既存)を最後のシートまで実行するには?

    エクセルのVBAで質問です。 現在、下記のVBAにて、エクセルに4色の色をつけています。 内容 ・処理範囲内(D5:AI50)の列の値が、 ・指定した行(4行目)の値から見て、 ・+5、+10、-5、-10の場合、それぞれ指定した色をつけています ・ただしC列の値が30未満の行は色付けなし 現状では、このマクロはアクティブシートのみで使えるため、 100シートあれば、それぞれのシートにおいて そのつどマクロを実行しています。 これを、一度の実行で最終シートまで実行できるようにしたいのです。 VBA初心者のため、見よう見まねでループを試してみたものの、 どうもうまく動きませんでした。 なにとぞご教授のほど、お願いいます。 ●以下、現在使用しているVBA Sub 条件付4色の標本数1() Dim 処理範囲 As Range Dim 先頭の行番号 As Long Dim 全体の行数 As Long Dim 各セル As Range Dim 差分 As Single Dim 標本数 As Single Set 処理範囲 = Range("D5:AI50") For Each 各セル In 処理範囲 標本数 = Cells(各セル.Row, "C").Value If 標本数 >= 30 Then 差分 = 各セル.Value - Cells(4, 各セル.Column).Value    Select Case 差分 Case Is <= -10 各セル.Interior.ColorIndex = 37 'ペールブルー 各セル.Font.ColorIndex = 1 Case Is <= -5 各セル.Interior.ColorIndex = 34 '薄い水色 各セル.Font.ColorIndex = 1 Case Is >= 10 各セル.Interior.ColorIndex = 6 '黄37 各セル.Font.ColorIndex = 1 Case Is >= 5 各セル.Interior.ColorIndex = 19 '薄い黄 各セル.Font.ColorIndex = 1 Case Else 各セル.Interior.ColorIndex = xlNone '無色 End Select End If Next End Sub

  • 選択セルの行全体の色付け

    仕事でエクセルを使う事が多く、特に列、行がたくさんある一覧を表を日常業務で使っています。そこで選択セルの行全体が色付けされるような仕組みを作りたく。(イメージ的には、今触っているセルがどの行なのか目で追い易くする感じです)このようなマクロを作りました。ただ、これでは元々色が付いているセルの色が、色無しに変化してしまう為、使えません。使っている表の元々の色を変化させずに、色で簡単に行全体を目で追えるようにするにはどうしたら良いでしょうか?本当に申し訳ないですが、わかる方いらっしゃいましたら、ご教授お願い致します。 Public m Private Sub Worksheet_SelectionChange(ByVal Target As Range)  If m <> 0 Then   Range(Cells(m, 1), Cells(m, 256)).Interior.ColorIndex = xlNone  End If  Range(Cells(Target.Row, 1), Cells(Target.Row, 256)).Interior.ColorIndex = 6  m = Target.Row End Sub

  • VBA 「文字が入っていたら、上下に線を引く」

    困っています。どなたか教えてください。 下記のように作成しましたが、 A列に文字が入っていたら、上下に線を引くというプロシージャにしたいと思っています。 If Cells(c, 4) = "" Then Range(Cells(c, 1), Cells(c, 6)).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With bolFlg = True Else まだまだ続きますが・・・・。 よろしくお願いいたします。

  • ワークシートのセルの書式設定の罫線をマクロでひく。

    ワークシートのセルの書式設定の罫線をマクロでひく。 下記マクロを実行すると  (1)のところでBORDERクラスのlinestyle プロパティを設定できません。がでる対策をおしえてください。 Sub Macro1() ' Dim d As Long Sheets("abc").Select '罫線を引く d = Range("A65536").End(xlUp).Row Range("A1", Cells(d, 1)).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  ‘(1) .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End Sub

  • vb6.0でEXCELオブジェクトの使用

    以下のプログラムで四苦八苦しております。 vb6.0だとエラーが出て、vbaだとエラーはなく正常に終了します。 (エクセルは2002です) ※vbは、「microsoft excel 10.0 object library」にチェックを 入れています。 vb6.0だと「w_range.Select」の下の行の 「With Selection.Borders(xlEdgeLeft)」で 「実行時エラー424 オブジェクトが必要です。」となります。 後、「microsoft excel 10.0 object library」にチェックを入れる 事によって、vbaで作成できるプロバティ・メッソド等は使用できる と考えていいのでしょうか? ************** Private Sub Form_Load() Dim xls_csv As Object Dim w_range As Object Set xls_csv = CreateObject("Excel.Sheet") Set xls_kei = CreateObject("Excel.Sheet") xls_csv.Sheets(1).Name = "test" xls_csv.Application.Visible = True With xls_csv.Worksheets(1) .Cells(1, 2).Value = "aaa" .Cells(1, 3).Value = "bbb" .Cells(1, 4).Value = "ccc" End With With xls_csv.Worksheets(1) Set w_range = .Range(.Cells(1, 2), .Cells(10, 4)) End With w_range.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 End Sub **************

  • EXCEL セルをコピペすると画面がフリーズする

    お世話になります excelシート イベントでセルの値が変わった時にマクロが実行されるVBAを作成していて、 1行毎の入力作業はうまくいくのですが、式の入っていないセルを複数行をコピペ、 例えばA,Bセルの値が同じものが5件ほどあった場合、最初の入力のものをしたにドラッグして 貼り付けると、画面がフリーズして強制終了せざる負えなくなります。 エラーを回避する方法をご教示お願いいたします。以下VBAの内容です。 Dim sh1 As Worksheet Dim i As Integer Private Sub Worksheet_Calculate() 'detailに指標をセット i = 9 シートをworkエリアにセット Set sh1 = Worksheets(4) 'カードルシート,2ページ(予備)まで指標を回す For i = 9 To 66 '画面ちらつき防止 Application.ScreenUpdating = False '2ページ(予備)目ヘッダーは処理しない If i < 33 Or i > 41 Then 'サンプル番号が入力されている時 If sh1.Cells(i, "E") <> "" Then 'サンプル年月が入力されている時 If IsError(sh1.Cells(i, "K")) <> True Then '基準年月 >= サンプル年月 の時 If sh1.Cells(7, "O") >= sh1.Cells(i, "K") Then '次回サンプル年月 <= 当年月 の時 If sh1.Cells(i, "Q") <= sh1.Cells(8, "O") Then sh1.Cells(i, "M") = "出荷禁止" '該当行を赤色で塗りつぶし With sh1 .Cells(i, "A").Interior.ColorIndex = 3 .Cells(i, "B").Interior.ColorIndex = 3 .Cells(i, "C").Interior.ColorIndex = 3 .Cells(i, "D").Interior.ColorIndex = 3 .Cells(i, "E").Interior.ColorIndex = 3 .Cells(i, "F").Interior.ColorIndex = 3 .Cells(i, "G").Interior.ColorIndex = 3 .Cells(i, "H").Interior.ColorIndex = 3 .Cells(i, "I").Interior.ColorIndex = 3 .Cells(i, "J").Interior.ColorIndex = 3 .Cells(i, "K").Interior.ColorIndex = 3 .Cells(i, "L").Interior.ColorIndex = 3 .Cells(i, "M").Interior.ColorIndex = 3 End With Else '次回サンプル年月 <= 当年月 でない時 sh1.Cells(i, "M") = "OK" End If End If End If Else '該当行を無色で塗りつぶし With sh1 .Cells(i, "A").Interior.ColorIndex = 0 .Cells(i, "B").Interior.ColorIndex = 0 .Cells(i, "C").Interior.ColorIndex = 0 .Cells(i, "D").Interior.ColorIndex = 0 .Cells(i, "E").Interior.ColorIndex = 0 .Cells(i, "F").Interior.ColorIndex = 0 .Cells(i, "G").Interior.ColorIndex = 0 .Cells(i, "H").Interior.ColorIndex = 0 .Cells(i, "I").Interior.ColorIndex = 0 .Cells(i, "J").Interior.ColorIndex = 0 .Cells(i, "K").Interior.ColorIndex = 0 .Cells(i, "L").Interior.ColorIndex = 0 .Cells(i, "M").Interior.ColorIndex = 0 .Cells(i, "M") = "" End With End If End If Next i End Sub

  • セル色を5秒間隔で変える

    マクロ作成でセルに色を3色順次に変わるようにしたいのですが、 セル色の変更時間が早く、最後の色のみの表示になります。 コマンドボタンをクリックすると、アクティブセル(B3からF3)までのセル色が黄色・薄青・赤に5秒間隔で変色し、その後、下のセルに移動します。 再度、コマンドボタンをクリックすると、先ほどの上のセルの色が消え、アクティブセルに黄色・薄青・赤に5秒間隔で変更するVBAをお教えください。マクロで作成したVBを表示しておきます。 {timer}を使用するみたいですが、理解出来ませんので、宜しくお願いします。 罫線も引いてあります。 ActiveCell.Range("A1:E1").Select With Selection.Interior Timer = 4 .ColorIndex = 35 .Pattern = xlSolid End With Selection.Interior.ColorIndex = xlNone With Selection.Interior .ColorIndex = 7 .Pattern = xlSolid End With Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With Selection.Borders(xlInsideVertical).LineStyle = xlNone ActiveCell.Offset(1, 0).Range("A1:E1").Select End Sub

専門家に質問してみよう