Cells(4, 6).Offset(0, 1).Interior.Color = Cells(4, 6).Interior.Color
上面VBA执行后则将(4,6)单元格的颜色向右偏移一格填充(4,6)颜色
将(0,1)换成(0,-1)则是向左偏移填充颜色
执行下面的宏代码
Sub a()
For i = 2 To 100 '假设有99行要涂色的数据
If Cells(i, 3) <> "" Then
Cells(i, 3).Offset(0, 1).Interior.Color = Cells(i, 3).Interior.Color '向右的一个单元格填充颜色
Cells(i, 3).Offset(0, 2).Interior.Color = Cells(i, 3).Interior.Color '向右的第二个单元格填充颜色
Cells(i, 3).Offset(0, -1).Interior.Color = Cells(i, 3).Interior.Color '向左的一个单元格填充颜色
Cells(i, 3).Offset(0, -2).Interior.Color = Cells(i, 3).Interior.Color '向左的第二个单元格填充颜色
End If
Next
End Sub
温馨提示:答案为网友推荐,仅供参考