我编写了一些代码,它将更改单元格的背景颜色,但我只想更改单元格内容的颜色。
我试图寻找正确的代码,但无法用我的代码修复它。
Sub cellColor()
Dim colCount As Integer
Dim count As Integer
colCount = Selection.Tables(1).Columns.count
col = 0
If Selection.Shading.BackgroundPatternColor = RGB(255, 255, 255) Then
While col < colCount
Selection.Shading.BackgroundPatternColor = RGB(255, 114, 86)
col = col + 1
Wend
Else
Selection.Shading.BackgroundPatternColor = RGB(255, 255, 255)
End If
Exit Sub
End Sub
您需要使用单元格范围的Shading
,而不是Selection
范围。
这应该起作用:
Selection.Cells(1).Range.Font.Shading.BackgroundPatternColor = RGB(255, 114, 86)