Board logo

標題: excel聚光灯怎樣不影響原來格式上的顏色 [打印本頁]

作者: coke373    時間: 2020-5-13 13:15     標題: 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
複製代碼
怎樣解決關掉之後可以刪除聚光燈
作者: 准提部林    時間: 2020-5-13 14:15

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
作者: 准提部林    時間: 2020-5-13 14:23

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
作者: coke373    時間: 2020-5-13 14:38

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

回復 4# coke373


紅色那行刪除
作者: coke373    時間: 2020-5-13 14:53

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




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)