2016-07-15 16 views
0

定義済みのセルの値(この場合はセル "H")に応じて、セル範囲(「A」から「N」)の色を変更しようとしています。 「資格認定」、「CIエラー/チケット」、「完了/バックアップ」の場合は白と太字に変更する必要があり、それ以外の場合は定期的にブラックにしてください。条件付き書式でのフォント色の変更

定義された範囲でセルの色を変更するコードがありますが、フォントスタイルと色を変更するコードを適用する方法がわかりません。

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Not Intersect(Target, Columns("H")) Is Nothing Then 
     On Error GoTo bm_Safe_Exit 
     Application.EnableEvents = False 
     Dim trgt As Range 
     For Each trgt In Intersect(Target, Columns("H")) 
      Select Case LCase(trgt.Value2) 
      Case "2 day process" 
        Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 46 
        Case "advisor" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "back in" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 22 
        Case "ci error/ticket" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 1 
        Case "completed" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 10 
        Case "completed/backup" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 51 
        Case "credentialing" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 49 
        Case "credit" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 44 
        Case "duplicate" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 10 
        Case "held" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "master data" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "name change" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "ofr" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 3 
        Case "op consultant" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "post process" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 32 
        Case "pps" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "react acct" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case "rejected" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 10 
        Case "transferred" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 10 
        Case "zpnd" 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.ColorIndex = 37 
        Case Else 
         Cells(trgt.Row, "A").Resize(1, 14).Interior.Pattern = xlNone 
      End Select 
     Next trgt 
    End If 
bm_Safe_Exit: 
    Application.EnableEvents = True 
    End Sub 
+0

https://msdn.microsoft.com/en-gb/library/office/ff838238.aspx&https://msdn.microsoft.com/en-gb/library/office/ ff196273.aspxがお手伝いします。 –

答えて

1

あなたは細胞のFontプロパティにアクセスする必要があります。ここに私はこれまで持っているものです。だからあなたの場合

Cells(trgt.Row, "A").Resize(1, 14).Font.ColorIndex = 1 
Cells(trgt.Row, "A").Resize(1, 14).Font.FontStyle = "Bold" 
+0

ありがとうございます。私の質問に記載されているケースについては、ワークシートにコードを適用しましたが、希望のセル範囲のフォントプロパティを変更していません。私は似たようなことを試みましたが、色を変えていました。問題は、値を変更したり、セル "H"の値を削除したときにフォントがまだ白で、デフォルトに変更する必要があるという問題でした – rogiefc

関連する問題