Excel技巧:选中数据,十字交叉高亮显示!

选中数据 十字交叉高亮显示
代码1
Private Sub Workbook _SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)Sh.Cells.Interior.Colorindex = xlNone
Target.EntireColumn.Interior.Colorindex = 36
Target.EntireRow.Interior.Colorindex = 36
End Sub
用法:复制这段代码~找到 开发工具~点击Visual Basic~点击ThisWordBook~把代码复制进去就好
原理:清除所有单元格的填充颜色,只对选中单元格的行和列进行填充颜色
不足之处:如果其他单元格原本有填充的颜色,那会被清除掉
代码2
Private Sub Workbook _SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireColumn
.FormatConditions.Add xlExpression,, " =true"
.FormatConditions(1).lnterior.Colorindex = 20 End With
With Target.EntireRow
.FormatConditions. Add xlExpression, , " =true"
.FormatConditions(2).lnterior.Colorindex = 20 EndWith
End Sub
用法同上
原理:条件格式原理,首先清除掉所有单元格的条件格式,再对已有颜色的单元格进行重新设置条件格式
优点:可以保留原有单元格的填充颜色