使用VBA在Excel中着色一系列单元格

1 vba range cell excel-vba background-color

我有一个电子表格,我在工作中用来跟踪退回的合同.我已经设置了一个颜色键,因此我可以快速浏览一下表格,看看哪些合同仍然需要退回给我们以及该帐户所属的帐户经理.

客户经理的姓名缩写列在A栏; 从那里我想为该行中的单元格范围着色(A:H),具体取决于在A中输入的首字母.现在我有以下代码,但我不喜欢电子表格的外观整行有色:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column <> 1 Then Exit Sub

Select Case Target

Case "MKH"
Target.EntireRow.Interior.ColorIndex = 36

Case "MAH"
Target.EntireRow.Interior.ColorIndex = 39

Case "MJM"
Target.EntireRow.Interior.ColorIndex = 34

Case "JVE"
Target.EntireRow.Interior.ColorIndex = 35

Case Else
Target.EntireRow.Interior.ColorIndex = 0

End Select
Run Code Online (Sandbox Code Playgroud)

PS我们办公室的大多数工作人员仍在使用Office 2003,因此不能选择条件格式.

Tob*_*ias 6

如果您的问题是如何为行的一部分而不是整个行着色,这应该工作:

Range("A" & Target.Row, "H" & Target.Row).Interior.ColorIndex = 10
Run Code Online (Sandbox Code Playgroud)