Excel技巧:選中數(shù)據(jù),十字交叉高亮顯示!

選中數(shù)據(jù) 十字交叉高亮顯示
代碼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
用法:復(fù)制這段代碼~找到 開發(fā)工具~點(diǎn)擊Visual Basic~點(diǎn)擊ThisWordBook~把代碼復(fù)制進(jìn)去就好
原理:清除所有單元格的填充顏色,只對選中單元格的行和列進(jìn)行填充顏色
不足之處:如果其他單元格原本有填充的顏色,那會被清除掉
代碼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
用法同上
原理:條件格式原理,首先清除掉所有單元格的條件格式,再對已有顏色的單元格進(jìn)行重新設(shè)置條件格式
優(yōu)點(diǎn):可以保留原有單元格的填充顏色