在工作表"sheet1"按滑鼠右鍵,
會顯示功能表,選"檢視程式碼",
或是按"Alt+F11"。
會出現以下畫面,
貼上
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"。
不管用滑鼠點儲存格或移動儲存格,
整列都會變顏色。
若要整欄變顏色,
請貼上
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
這些都是查找到的資訊,
不會清除儲存格原本的顏色
- Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
- On Error Resume Next
- If Target.Count > 1 Then Exit Sub
- Cells.FormatConditions.Delete
- With Target.EntireColumn.FormatConditions '
- .Delete
- .Add xlExpression, , "TRUE"
- .Item(1).Interior.ColorIndex = Int(35)
- End With
- With Target.EntireRow.FormatConditions '这是行变色
- .Delete
- .Add xlExpression, , "TRUE"
- .Item(1).Interior.ColorIndex = Int(35)
- End With
- With Target.FormatConditions '这是单元格变色
- .Delete
- .Add xlExpression, , "TRUE"
- .Item(1).Interior.ColorIndex = Int(4)
- End With
- End Sub
我覺得這個太長了,
應該再找個簡單一點。
留言列表