首页>资讯>专题>详情页

高亮颜色标记单元格、行、列、行列实例【excel实用教程】

2010-11-05 11:36

高亮颜色标记单元格、行、列、行列实例

  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

继续阅读与本文标签相同的文章

免责声明:本文章和图片均来至于网络和网络上传,如有侵权请及时联系cs@jdy.com给与删除

相关推荐