优易学—国内最大的教育考试网站之一
您现在的位置: 优易学 >> 财会考试 >> 实务操作 >> 会计电算化 >> 巧用EXCEL >> 正文

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

2011-9-24 18:05:54 来源:优易学 作者:YouYiXue.com   【 】【打印
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

责任编辑:八月骄阳
如果你有什么问题需要咨询或帮助,请联系我们的客服QQ:53882478
关于我们合作加盟广告联系联系我们网站地图网站声明友情链接优易学QQ群联盟最新更新团队博客
热线:019-52880094 传真:010-52880094
投诉意见,请点这里在线提交或24小时QQ热线:53882478
Copyright © 2005-2012 YouYiXue.com All Rights Reserved 京ICP备09036865号-3