2017-04-22 19 views
-1

0を含む特定の行のセルを見つけるコードを作成しようとしています。このセルは、下の8セルを白い背景と白のフォントにフォーマットします。基本的には細胞を見えないようにする。理想的には、検索されたセル内にXがある場合、8個のセルを元のフォーマットに戻すことができるようにしたいと思います。VBA Excel - セルを見つけて下のセルをフォーマットする

Sample Data

は、残念ながら私は新しいユーザーだと例の画像を表示することができませんので、上記のリンクをクリックしてください-thanks。

+0

の列に存在したならば、以前に戻すフォントを変更する2番目のマクロを追加して、ではなく、それらを識別するために、どのように私たちに語りました。コードはどのように開始するのかを知っていますか? –

+1

これまでに書いたコードを共有してください。 –

+0

私は以下の答えを書いていますが、条件付き書式でこれを行うことができます。 –

答えて

0

あなたは私たちの質問に答えていないので、以下はあなたが望むものではないかもしれませんが、それは良いスタートでなければなりません。

Sub Hide8CellsBelow0() 

    Dim arrayRowNumbers() As Variant 
    arrayRowNumbers = Array(2, 12) ' <-- "Specific Rows" 

    Dim intRow As Integer 
    Dim objCell As Range 

    For intRow = 0 To UBound(arrayRowNumbers) 

     For Each objCell In ThisWorkbook.ActiveSheet.Rows(arrayRowNumbers(intRow)).Cells 

      Debug.Print objCell.Address & " : " & objCell.Value 

      If objCell.Text = "" Then Exit For ' <-- Quit the row after finding an empty cell 
      If objCell.Value = 0 Then 

       With Range(objCell.Offset(1), objCell.Offset(8)) 
        'I got the following from recording a Macro, you don't have to remember everything 
        With .Interior 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
        .ThemeColor = xlThemeColorDark1 
        .TintAndShade = 0 
        .PatternTintAndShade = 0 
        End With 
        With .Font 
        .ThemeColor = xlThemeColorDark1 
        .TintAndShade = 0 
        End With 
       End With 

      End If 

     Next objCell 

    Next intRow 

End Sub 
0

ありがとうスティーブ!私は過去数時間のうちに反応しなかったことを謝罪します。私は家族と地球の日の清掃に出かけていました。

8、18、28の「特定の行」を見るために少し変更しました。予想どおりに動作します。私はXの代わりにあなたが「特定の行に」言った0

Sub Hide8CellsBelow0() 

Dim arrayRowNumbers() As Variant 
arrayRowNumbers = Array(8, 18, 28) ' <-- "Specific Rows" 

Dim intRow As Integer 
Dim objCell As Range 

For intRow = 0 To UBound(arrayRowNumbers) 

    For Each objCell In ThisWorkbook.ActiveSheet.Rows(arrayRowNumbers(intRow)).Cells 

     Debug.Print objCell.Address & " : " & objCell.Value 

     If objCell.Text = "" Then Exit For ' <-- Quit the row after finding an empty cell 
     If objCell.Value = 0 Then 

      With Range(objCell.Offset(1), objCell.Offset(8)) 
       'I got the following from recording a Macro, you don't have to remember everything 
       With .Interior 
       .Pattern = xlSolid 
       .PatternColorIndex = xlAutomatic 
       .ThemeColor = xlThemeColorDark1 
       .TintAndShade = 0 
       .PatternTintAndShade = 0 
       End With 
       With .Font 
       .ThemeColor = xlThemeColorDark1 
       .TintAndShade = 0 
       End With 
      End With 

     End If 

    Next objCell 

Next intRow 

End Sub 

Sub Show8CellsBelowX() 

Dim arrayRowNumbers() As Variant 
arrayRowNumbers = Array(8, 18, 28) ' <-- "Specific Rows" 

Dim intRow As Integer 
Dim objCell As Range 

For intRow = 0 To UBound(arrayRowNumbers) 

    For Each objCell In ThisWorkbook.ActiveSheet.Rows(arrayRowNumbers(intRow)).Cells 

     Debug.Print objCell.Address & " : " & objCell.Value 

     If objCell.Text = "" Then Exit For ' <-- Quit the row after finding an empty cell 
     If objCell.Value = "X" Then 

      With Range(objCell.Offset(1), objCell.Offset(1)) 
       With .Interior 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
        .Color = 65535 
        .TintAndShade = 0 
        .PatternTintAndShade = 0 
       End With 
       With .Font 
        .Color = -16776961 
        .TintAndShade = 0 
       End With 
      End With 

      With Range(objCell.Offset(2), objCell.Offset(2)) 
       With .Font 
        .ColorIndex = xlAutomatic 
        .TintAndShade = 0 
       End With 
      End With 

      With Range(objCell.Offset(3), objCell.Offset(3)) 
       With .Interior 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
        .Color = 10079487 
        .TintAndShade = 0 
        .PatternTintAndShade = 0 
       End With 
       With .Font 
        .Color = -16776961 
        .TintAndShade = 0 
       End With 
      End With 

      With Range(objCell.Offset(4), objCell.Offset(4)) 
       With .Interior 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
        .Color = 13434828 
        .TintAndShade = 0 
        .PatternTintAndShade = 0 
       End With 
       With .Font 
        .Color = -16776961 
        .TintAndShade = 0 
       End With 
      End With 

      With Range(objCell.Offset(5), objCell.Offset(6)) 
       With .Font 
        .ColorIndex = xlAutomatic 
        .TintAndShade = 0 
       End With 
      End With 

      With Range(objCell.Offset(7), objCell.Offset(8)) 
       With .Font 
        .Color = -16776961 
        .TintAndShade = 0 
       End With 

      End With 

     End If 

    Next objCell 

Next intRow 

End Sub 
関連する問題