• ベストアンサー

For Nextマクロの高速化についてご教示ください。

Wendy02の回答

  • Wendy02
  • ベストアンサー率57% (3570/6232)
回答No.2

こんばんは。 私には良く分からないですが、ひとつだけ、Application.StatusBar に表示するというのは、遅いという問題があるとしたら、それは余計だと思います。このマクロは、トグルになっていますので、もう一度すれば、戻ります。 '----------------------------------- Sub 行列非表示R()   Dim ArI() As String   Dim ArN() As String   Dim i As Long, x As Long, y As Long, n As Long   Dim a As Long, b As Long, e As Long, f As Long      With ActiveSheet     e = .UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count     f = .UsedRange.Rows.Count     x = .Cells(1, 1).SpecialCells(xlLastCell).Row     y = .Cells(1, 1).SpecialCells(xlLastCell).Column   If f <= 1 And y <= 1 Then     MsgBox "現在のシートの状態ではマクロは不可能かもしれません。", 48     Exit Sub   End If   If e <> f Then    'トグルになっている     .Cells.Rows.RowHeight = .StandardHeight     .Cells.Columns.ColumnWidth = .StandardWidth     Exit Sub   End If   'Main   Application.Calculation = xlCalculationManual   Application.ScreenUpdating = False     For i = 2 To x       If .Cells(i, 1).Interior.ColorIndex = 3 Then         ReDim Preserve ArI(a)         ArI(a) = .Cells(i, 1).Address(0, 0)         a = a + 1       End If     Next i     For n = 1 To y       If .Cells(1, n).Interior.ColorIndex = 3 Then         ReDim Preserve ArN(b)         ArN(b) = .Cells(1, n).Address(0, 0)         b = b + 1       End If     Next n     .Range(Join(ArI(), ",")).EntireRow.Hidden = True     .Range(Join(ArN(), ",")).EntireColumn.Hidden = True   End With   Application.Calculation = xlCalculationAutomatic   Application.ScreenUpdating = True End Sub

merlionXX
質問者

お礼

ありがとうございます。 非表示にした行列を表示するのは、 Private Sub 行列表示() With ActiveSheet .Cells.EntireRow.Hidden = False .Cells.EntireColumn.Hidden = False End With End Sub で、瞬時に出来ますのでトグルにする必要はないんでが、そのままやってみたところ、「実行時エラー1004 アプリケーション定義またはオブジェクト定義のエラーです」となってしまいます。 .Range(Join(ArI(), ",")).EntireRow.Hidden = True がひっかかるようです。どこがわるいのでしょうか?

merlionXX
質問者

補足

ちなみにエラーになった.Range(Join(ArI(), ",")).EntireRow.Hidden = True の、Join(ArI(), ",")の中身は、 A76,A77,A78,A79,A80,A81,A82,A83,A84,A85,A86,A87,A88,A89,A90,A91,A92,A93,A94,A95,A96,A97,A98,A99,A100,A101,A102,A103,A104,A105,A106,A107,A108,A109,A110,A111,A112,A113,A114,A115,A116,A117,A118,A119,A120,A121,A122,A123,A124,A125,A126,A127,A128,A129,A130,A131,A132,A133,A134,A135,A136,A137,A138,A139,A140,A141,A142,A143,A144,A145,A146,A147,A148,A149,A150,A151,A152,A153,A154,A155,A156,A157,A158,A159,A160,A161,A162,A163,A164,A165,A166,A167,A168,A169,A170,A171,A172,A173,A174,A175,A176,A177,A178,A179,A180,A181,A182,A185   でした。 多すぎるのでしょうか?

関連するQ&A

  • エクセルVBAで複数シートにマクロ実行

    エクセル2000です。 Sub 行列非表示() For i = 2 To 120 If Cells(i, "A").Interior.ColorIndex = 3 Then Cells(i, "A").EntireRow.Hidden = True End If Next i For n = 1 To 50 If Cells(1, n).Interior.ColorIndex = 3 Then Cells(1, n).EntireColumn.Hidden = True End If Next n End Sub 上記マクロを、シートAAAとCCCとEEEに実行する場合、 Sub test() Sheets("AAA").Activate Call 行列非表示 Sheets("CCC").Activate Call 行列非表示 Sheets("EEE").Activate Call 行列非表示 End Sub と書くよりももっとすっきり実行する方法は無いでしょうか? 各シートの非表示対象の行や列はそれぞれことなります。 また Sub 行列非表示 自体も、もっと効率的にやる方法はないでしょうか?

  • マクロ 色が思うように、表示できない

     下記のようなコードで部品の管理をしています。条件が多くて少し複雑になっています。 とりあえずは、うまくできました。J列の結果だけが、うまくできません。 但し、J列の結果が(38はローズ )の表示がうまくいきません。(6の黄色)になってしまいます。 要するに、J列の結果が不がローズ色で、合が白色で、欠が薄いオレンジ色になればよいということなのです。 原因が分からず困ってしまって、お聞きする次第です。回答して頂けるものでしようか。 ご教授下されば幸いに存じます。よろしくお願いします。  Macro2 Macro マクロ記録日 : ' Sheets("sheet1").Select Columns("A:J").Select Selection.Copy Sheets("sheet2").Select Columns("A:J").Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _ :=xlPinYin, DataOption1:=xlSortNormal Dim i As Long, LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row Range("J2:J" & LastRow).ClearContents '← E2:Jにすると、欠に全部なります、この設定もおかしいように思いますが? Range("E2:J" & LastRow).Interior.ColorIndex = 0 Application.ScreenUpdating = False Application.Calculation = xlCalculationManual '文言の詳細について '部品名と詳細-------------------------------------略称            'ghyu--------------------------------------←E列   'klub---------------------------------------←F列  'llpo----------------------------------------←G列  '合計個数(合計)-------------------------←H列  合計   '数量順位---------------------------------←I列   順位 '合格・不合格(合・不)欠品(欠)-----←J列  合・不・欠 If Cells(i, "E") >= 1 And Cells(i, "E") < 20 Then Cells(i, "E").Interior.ColorIndex = 6 ' 6は  黄色 End If If Cells(i, "F") >= 1 And Cells(i, "F") < 6 Then Cells(i, "F").Interior.ColorIndex = 6 ' 6は  黄色  End If If Cells(i, "F") >= 6 And Cells(i, "F") < 10 Then Cells(i, "F").Interior.ColorIndex = 34 '34は  淡い青色 End If If Cells(i, "G") >= 1 And Cells(i, "G") < 10 Then Cells(i, "G").Interior.ColorIndex = 6 ' 6は  黄色  End If If Cells(i, "H") >= 1 And Cells(i, "H") <= 49 Then Cells(i, "H").Interior.ColorIndex = 4 ' 4は  うぐいす色  End If If Cells(i, "J") >= "不" Then Cells(i, "J").Interior.ColorIndex = 38 '38は ローズ    End If If Cells(i, "J") >= "合" Then Cells(i, "J").Interior.ColorIndex = 2 ' 2は  白色  End If For j = 5 To 9 'D-F If Cells(i, j).Value = 0 Then Cells(i, j).Interior.ColorIndex = 3 '3は    赤色        ElseIf Cells(i, j).Value = "欠" Then Cells(i, j).Interior.ColorIndex = 45 '45は  薄いオレンジ色     End If Next j For k = 5 To 9 'G-I If Cells(i, j).Value = "欠" Then Cells(i, j).Interior.ColorIndex = 45 '45は  薄いオレンジ色   End If Next k Next i Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub

  • 行ごとに判定するマクロについて教えて下さい

    行ごとに判定するマクロについて教えて下さい。 下記のようなマクロで、添付ファイルのように、行ごとで E列からN列で違った数値がないか、入力されていないセルがないかを調べ 4つすべてのセルが同じ数値でない場合は塗りつぶしはされず O列にOKを表示しないようなマクロを組みたいのですが 現在のマクロだと、行ごとではなく、E3~N102セルまでの中で 同じ数値がないかを判断してしまっているため K11セルやK15セルのように数値が入力されていないにも関わらずO列の部分にOKが出てしまいます。 他の行に同じ数値が入っているのは関係なしにして 11行目なら11行目だけで 15行目なら15行目だけで、というように行ごに判定していくには どのようにすればいいでしょうか? Sub 判定マクロ回転() Dim i As Integer, j As Integer Range(Cells(3, 15), Cells(102, 15)).ClearContents For i = 3 To 102 For j = 5 To 14 Cells(i, j).Interior.ColorIndex = 0 If WorksheetFunction.CountIf(Range("E3:N102"), Cells(i, j)) > 3 Then If Cells(i, j).Row Mod 2 = 1 Then Cells(i, j).Interior.ColorIndex = 6 Cells(i, 15) = "OK" Else If Cells(i, j).Row Mod 2 = 0 Then Cells(i, j).Interior.ColorIndex = 40 Cells(i, 15) = "OK" End If End If End If Next j Next i If WorksheetFunction.CountIf(Range("O3:O102"), "OK") > 99 Then MsgBox "データチェックOK(^O^)b" End If End Sub

  • マクロ 検索範囲を修正したい 1つ置きのセルで

    前に以下のマクロをここで教えていただきました。このときはB列からF列の範囲でお願いしたのですが、F列~AG列の1つ置きのセル(G、I、K・・・列)で検索したいです。どう修正したらよいですか?初心者なので調べても分からなかったので教えてください。 Sub Sample1() 'この行から Dim i As Long, j As Long, vL vL = InputBox("検索値を入力してください。") Application.ScreenUpdating = False Cells.Interior.ColorIndex = xlNone For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row For j = 2 To 5 With Cells(i, j) If .Value <> "" And .Value >= vL - 3 And .Value <= vL + 3 Then .Interior.ColorIndex = 36 End If End With Next j Next i Application.ScreenUpdating = True 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

  • エクセル マクロ 複数セルの色付けについて

    マクロ初心者で苦戦しており、教えていただけると大変ありがたいです。 エクセルの複数のシートに、問2_1 、問2_2 、問2_10 (全部で問は2_28まであります)等の文字列があり、その文字に合わせて、そのセルだけ色を付けたいと考えております。 今書いているコードだと、ワークシートのA列にある場合は色が付けられるのですが、それ以外に色が付けられません。どこが間違っているでしょうか? どうぞご指導お願いいたします。 Sub 色つけ() Dim Maxrow As Long Dim i As Long Maxrow = Cells(Rows.Count, i).End(xlUp).Row For i = 1 To Maxrow If InStr(Cells(i, 1), "2_1 ") > 0 Then Cells(i, 1).Interior.ColorIndex = 6 If InStr(Cells(i, 1), "2_2 ") > 0 Then Cells(i, 1).Interior.ColorIndex = 6 If InStr(Cells(i, 1), "2_23 ") > 0 Then Cells(i, 1).Interior.ColorIndex = 23 If InStr(Cells(i, 1), "2_13 ") > 0 Then Cells(i, 1).Interior.ColorIndex = 4 If InStr(Cells(i, 1), "2_6 ") > 0 Then Cells(i, 1).Interior.ColorIndex = 7 Next i End Sub

  • 全体を表示 マクロ 色が思うように、表示できない

     「マクロ 色が思うように、表示できない」で質問したことへの追加になります。「S1299792さん」から、全体を表示しないと回答がしずらいことの指摘がありました。すみませんでした。その通りだと思いましたので、再度質問させて頂きました。 また、「watabe007さん」からの回答からコピー貼り付けの部分を教えて頂いたものも使って、改めてコードを書き換えて示します。  現在コピー貼り付け・ソート・J;列以外はコード通りに出来上がっています。それにJ列の欠・合も指示通りにできています。不だけがピンク色になりません。 なお、なぜか一カ所だけピンクになっているところがあります。条件の「条件 合計」・「条件 不合格」最初のEの不のところの条件だけは、ピンクになっています。  下記のが全体のコードです。 Sub 条件つきソート色つけ() Dim LastRow As Long, i As Long   Application.ScreenUpdating = False   Application.Calculation = xlCalculationManual   With Sheets("sheet1")     LastRow = .Cells(Rows.Count, "A").End(xlUp).Row     .Range("A1:J" & LastRow).Copy Sheets("sheet2").Range("A1")   End With   Application.CutCopyMode = False   Sheets("Sheet2").Select   Range("A1:J" & LastRow).Sort Key1:=Range("H1"), _     Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _     MatchCase:=False, Orientation:=xlTopToBottom, _     SortMethod:=xlPinYin, DataOption1:=xlSortNormal   Range("E2:J" & LastRow).Interior.ColorIndex = 0 '文言の詳細について '部品名と詳細---------------------------------------略称            'ghyu--------------------------------------←E列   'klub---------------------------------------←F列  'llpo----------------------------------------←G列  '合計個数(合計)-------------------------←H列  合計   '数量順位---------------------------------←I列   順位 '合格・不合格(合・不)欠品(欠)-----←J列  合・不・欠 For i = 2 To LastRow If Cells(i, "E").Value = "" Then Cells(i, "E").Resize(, 6).Value = "欠" 'E列 ElseIf Application.CountIf(Cells(i, "E").Resize(, 6), "欠") > 0 Then Cells(i, "J").Value = "欠" ElseIf Cells(i, "H") >= 1 And Cells(i, "H") <= 49 Then '条件 合計 Cells(i, "J") = "不" ElseIf (Cells(i, "E") >= 20 And Cells(i, "F") >= 6) And Cells(i, "G") >= 10 Then '条件 これ以上は合格 Cells(i, "J") = "合" ElseIf (Cells(i, "E") = 0 Or Cells(i, "F") = 0) Or Cells(i, "G") = 0 Then '条件 全て0で不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "E") <= 19) Then '条件  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "F") <= 5) Then '条件  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "F") <= 10) Then '条件  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "E") >= 20 And Cells(i, "F") >= 6) And Cells(i, "G") <= 9 Then '条件 E=○ F=○ G=×  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "E") >= 20 And Cells(i, "F") <= 5) And Cells(i, "G") <= 9 Then '条件 E=○ F=× G=×  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "E") <= 19 And Cells(i, "F") >= 6) And Cells(i, "G") <= 9 Then '条件 E=× F=○ G=×  不合格 Cells(i, "J") = "不" ElseIf (Cells(i, "E") <= 19 And Cells(i, "F") <= 5) And Cells(i, "G") >= 10 Then '条件 E=× F=× G=○  不合格 Cells(i, "J") = "不" End If If Cells(i, "E") >= 1 And Cells(i, "E") < 20 Then Cells(i, "E").Interior.ColorIndex = 6 ' 6は  黄色 End If If Cells(i, "F") >= 1 And Cells(i, "F") < 6 Then Cells(i, "F").Interior.ColorIndex = 6 ' 6は  黄色  End If If Cells(i, "F") >= 6 And Cells(i, "F") < 10 Then Cells(i, "F").Interior.ColorIndex = 34 '34は  淡い青色 End If If Cells(i, "G") >= 1 And Cells(i, "G") < 10 Then Cells(i, "G").Interior.ColorIndex = 6 ' 6は  黄色  End If If Cells(i, "H") >= 1 And Cells(i, "H") <= 49 Then Cells(i, "H").Interior.ColorIndex = 4 ' 4は  うぐいす色  End If If Cells(i, "J") >= "不" Then Cells(i, "J").Interior.ColorIndex = 38 '38は ローズ    If Cells(i, "J") >= "合" Then Cells(i, "J").Interior.ColorIndex = 2 ' 2は  白色  ElseIf Cells(i, "J") = "欠" Then Cells(i, "J").Interior.ColorIndex = 45 '45は  薄いオレンジ色 End If For j = 5 To 9 'D-F If Cells(i, j).Value = 0 Then Cells(i, j).Interior.ColorIndex = 3 '3は    赤色        ElseIf Cells(i, j).Value = "欠" Then Cells(i, j).Interior.ColorIndex = 45 '45は  薄いオレンジ色     End If Next j For k = 5 To 9 'G-I If Cells(i, j).Value = "欠" Then Cells(i, j).Interior.ColorIndex = 45 '45は  薄いオレンジ色   End If Next k Next i Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub

  • VBAで教えてください。

    以前ここで教えていただいたVBAで http://jisaku.155cm.com/src/1371930716_9b9006528605642980beed48a8998013b0731e4b.jpg のようにA列のテスト4をクリックしたときにC列のテスト4が一発で解るようにしたいです。 もちろん、テスト11をクリックしたときは、テスト4塗りつぶしは解除され、 テスト11が塗りつぶされるようにしたいです。 写真は塗りつぶししていますが、解るようにしたいだけなので、塗りつぶしにはこだわっていません。 あと、E、F、G列は解りやすく並べているだけで、実際はA、B、C列だけです。 それと、C列は関数を使って表示してあります。 という質問で Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'この行から Dim i As Long Range("C:C").Interior.ColorIndex = xlNone If Application.Intersect(Target, Range("A:A")) Is Nothing Or Target.Count <> 1 Then Exit Sub On Error Resume Next Application.ScreenUpdating = False ActiveSheet.Cells.interio.ColorIndex = xlNone For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row If Cells(i, "C") = Target Then Cells(i, "C").Interior.ColorIndex = 3 End If Next i Application.ScreenUpdating = True End Sub 'この行まで をシートのコードに張り付ければいいですよ。と教えてくれたものがあるのですが、 A列でクリックした文字をC列からすべて見つけて反転してくれないようです。何個か反転してくれない ものが出てきてしまいました。 C列が何百行とかなってしまうと、すべての同じ文字を検索してくれないのでしょうか? ちなみに列がここに掲載しているものと違うので Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'この行から Dim i As Long Range("R:R").Interior.ColorIndex = xlNone If Application.Intersect(Target, Range("B:B")) Is Nothing Or Target.Count <> 1 Then Exit Sub On Error Resume Next Application.ScreenUpdating = False ActiveSheet.Cells.interio.ColorIndex = xlNone For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row If Cells(i, "R") = Target Then Cells(i, "R").Interior.ColorIndex = 3 End If Next i Application.ScreenUpdating = True End Sub 'この行まで のCをRにAをBに変更して使ってます。 これがいけないのかな? よろしくお願いします。

  • エラー Nextに対するForがありませんについて

    VBAに慣れていないのですが、下記のマクロを組んでみました。 実行すると、コンパイルエラー Nextに対するForがありませんと出てしまいました。 原因が良く解らないので解る方いらっしゃいましたら教えてください。 それと、もっと良い書き方などありましたらアドバイスを下さい。 よろしくお願いします。 Sub レポート作成2each() Dim ReportMaxRow As Long '上方向に最終行を検索し行番号を格納 Dim AddWsName As String 'シート名格納 Dim Ws As Worksheet 'オブジェクト格納 Dim i As Long '繰り返しのカウントを格納 Dim flag As Boolean '真偽 ReportMaxRow = Worksheets("レポート元").Cells(Rows.Count, 1).End(xlUp).Row For i = 2 To ReportMaxRow If Cells(i, "N").Value <> "" Then If Cells(i, "O").Value <> "" Then AddWsName = Cells(i, "K").Value For Each Ws In Worksheets If Ws = AddWsName Then flag = True Next Ws   ←ここでエラーになります。 If flag = True Then Worksheets("レポート元").Cells(i, 1).EntireRow.Copy _ Destination:=Worksheets(AddWsName).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) Else Worksheets.Add ActiveWorksheet.Name = AddWsName Worksheets("レポート元").Cells(i, 1).EntireRow.Copy _ Destination:=Worksheets(AddWsName).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) End If MsgBox i + "行目の発注数の入力がませんでした。" & vbNewLine & "処理を中断します, _ vbOKOnly + vbExclamation, "お知らせ" End If Else MsgBox i + "行目の発注数の入力がませんでした。" & vbNewLine & "処理を中断します", _ vbOKOnly + vbExclamation, "お知らせ" End If Next i End Sub

  • 色付き行の非表示について

    いつもお世話になっております。 以前こちらで同様の質問が投稿されておりまして、そちらの回答を参考に(原文ほとんどそのままですが・・・)行折りたたみをしていたのですが、 もう少し改良出来るのではないかと思いご相談です。 参考質問は、かなり前に検索をしたので再検索出来なかったのですが・・・ 現在、 8行目からデータが入っております。 非表示にしたい行には任意の色で1行全体を色付けしています。 色のついていない行のみ 表示をします。 Sub hidden1() x = ActiveCell.SpecialCells(xlLastCell).Row y = ActiveCell.SpecialCells(xlLastCell).Column For i = x To 8 Step -1 For n = 1 To y If Cells(i, n).Interior.ColorIndex <> xlNone Then Rows(i).Hidden = True Next n Next i End Sub こちらですと、すべてのセルを検索し、行の非表示をしていると思います。(VBAの知識が無いので 間違っているかもしれません) 現在データ量は300行程ですので そんなに時間はかからないのですが、今後1000行、2000行と増えた場合の事を考え改良したいと思いました。 非表示にしたい行のA列には必ず色がついているので A列を検索し、色がついていればその行を非表示。 というようにする場合 上記どこの文を削れば良いのでしょうか? 出来れば 表示⇔非表示をボタン1個で切り替えられればと思っております。 もし、A列に非表示があれば表示する、 もし、A列に非表示がなければ色付き行を非表示にする というようなマクロを教えていただければ幸いです。 よろしくお願いいたします。