照明灯具防护等级:高亮颜色标记单元格、行、列、行列实例
来源:百度文库 编辑:偶看新闻 时间:2024/04/29 16:16:48
高亮颜色标记单元格、行、列、行列实例【excel实用教程】
2010-11-05 11:36:53 来源:中华会计网校 作者:i高亮颜色标记单元格、行、列、行列实例1.高亮颜色标记单元格
VBA代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
2.高亮颜色标记行
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
3.高亮颜色标记列
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
4.高亮颜色编辑行列
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
iColor = Int(50 * Rnd() + 2)
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = iColor
End With
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = iColor
End With
End Sub