在Excel 2013中着色单元格
我想在Excel 2013中查看一个命名的单元格区域,如果这些单元格中的文本是白色,那么我想将单元格右边的单元格的颜色设置为白色。 任何人都可以请帮助这个可怜的VBA编程newb出来? 非常感激。 祝你有美好的一天!
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Range("DateOut").Select For Each Cell In Selection If Cell.Font.ColorIndex = 2 Then Cell.Offset(, 1).Font.ColorIndex = 2 End If Next End Sub
代码工作正常
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Range("DateOut").Select For Each Cell In Selection If Cell.Font.ColorIndex = 2 Then Cell.Offset(, 1).Font.ColorIndex = 2 End If Next End Sub
哪一部分你有麻烦? 如果您在添加代码的位置遇到问题
- 右键单击表名并select查看代码并粘贴
请尝试:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) For Each Cell In Range("DateOut") If Cell.Font.ColorIndex = 2 Then Cell.Offset(, 1).Font.ColorIndex = 2 Next End Sub