返回列表 上一主題 發帖

excel聚光灯怎樣不影響原來格式上的顏色

excel聚光灯怎樣不影響原來格式上的顏色

  1. Private Sub CheckBox1_Click()
  2. If CheckBox1.Value = False Then
  3. CheckBox1.Caption = "關"
  4. ActiveSheet.Cells.Interior.ColorIndex = xlNone
  5. Else: CheckBox1.Caption = "開"
  6. End If
  7. End Sub
  8. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  9. If CheckBox1.Caption = "開" Then Call Spotlight(Target)
  10. End Sub
  11. Sub Spotlight(ByVal Target As Excel.Range)
  12. On Error Resume Next
  13. Cells.FormatConditions.Delete
  14. With Target.EntireColumn

  15.             .FormatConditions.Add xlExpression, , "=true"

  16.             .FormatConditions(1).Interior.ColorIndex = 20

  17.         End With

  18.         With Target.EntireRow

  19.             .FormatConditions.Add xlExpression, , "=true"

  20.             .FormatConditions(2).Interior.ColorIndex = 20

  21.         End With

  22. End Sub
複製代碼
怎樣解決關掉之後可以刪除聚光燈

回復 5# 准提部林
原來這樣刪除紅色那一行就可以了。謝謝准大大

TOP

回復 4# coke373


紅色那行刪除

TOP

回復 2# 准提部林
謝謝准大大
我試過加上這一句:Cells.FormatConditions.Delete
但是會把我原來表格上的所以顏色都刪除,請問准大是不是不能單獨刪除聚光燈的十字位。

TOP

Sub Spotlight(ByVal Target As Excel.Range)
Cells.FormatConditions.Delete
With Union(Target.EntireColumn, Target.EntireRow)
     .FormatConditions.Add xlExpression, , "=true"
     .FormatConditions(1).Interior.ColorIndex = 20
End With
End Sub

TOP

Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
   CheckBox1.Caption = "關"
  'ActiveSheet.Cells.Interior.ColorIndex = xlNone
  Cells.FormatConditions.Delete
Else: CheckBox1.Caption = "開"
End If
End Sub

TOP

        靜思自在 : 每天無所事事,是人生的消費者,積極、有用才是人生的創造者。
返回列表 上一主題