2016-07-15 49 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