在工作表"sheet1"按滑鼠右鍵,

會顯示功能表,選"檢視程式碼",

或是按"Alt+F11"。

2016-11-11_215331.jpg

會出現以下畫面,

貼上

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = xlCopy Then Exit Sub
Cells.Interior.ColorIndex = xlNone
Rows(Target.Row).Interior.ColorIndex = 24

End Sub

再按"x"或是按"Alt+F11"。

2016-11-11_220009.jpg

2016-11-11_220511.jpg

不管用滑鼠點儲存格或移動儲存格,

整列都會變顏色。

 

若要整欄變顏色,

請貼上

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = xlCopy Then Exit Sub
Cells.Interior.ColorIndex = xlNone
Columns(Target.Column).Interior.ColorIndex = 24
End Sub

若要整欄和整列變顏色,

請貼上

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = xlCopy Then Exit Sub
Cells.Interior.ColorIndex = xlNone
Union(Rows(Target.Row), Columns(Target.Column)).Interior.ColorIndex = 6
End Sub

 

 

這些都是查找到的資訊,

不會清除儲存格原本的顏色

  1. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  2.     On Error Resume Next
  3.      If Target.Count > 1 Then Exit Sub
  4.     Cells.FormatConditions.Delete
  5.     
  6. With Target.EntireColumn.FormatConditions  '
  7.         .Delete
  8.         .Add xlExpression, , "TRUE"
  9.         .Item(1).Interior.ColorIndex = Int(35)
  10.     End With
  11.     
  12. With Target.EntireRow.FormatConditions  '这是行变色
  13.         .Delete
  14.         .Add xlExpression, , "TRUE"
  15.         .Item(1).Interior.ColorIndex = Int(35)
  16.     End With
  17.     
  18. With Target.FormatConditions  '这是单元格变色
  19.         .Delete
  20.         .Add xlExpression, , "TRUE"
  21.         .Item(1).Interior.ColorIndex = Int(4)
  22.     End With
  23. End Sub

 

 

我覺得這個太長了,

應該再找個簡單一點。

 

 

arrow
arrow
    全站熱搜

    Ethel 發表在 痞客邦 留言(3) 人氣()