以下代码是论坛中有位老师制作的高亮显示选中的单元格,我要想改为高亮显示选中区域的行和列,谢谢!
Option Explicit
Declare Function GetCursorPos _
Lib "user32" ( _
lpPoint As POINTAPI) _
As Long
Type POINTAPI
x As Long
y As Long
End Type
Dim ChangeOn As Boolean
Dim OldRange As Range
Dim OldColorIndex As Integer
Dim blnStop As Boolean
Sub StopChange()
On Error Resume Next
If Not blnStop Then
blnStop = True
End If
End Sub
Sub ChangeColor()
Dim LngCurPos As POINTAPI
Dim NewRange As Range
On Error Resume Next
blnStop = False
If ChangeOn Then
Exit Sub
Else
ChangeOn = True
End If
Do
If blnStop = True Then Exit Do
GetCursorPos LngCurPos
On Error Resume Next
Set NewRange = ActiveWindow.RangeFromPoint(LngCurPos.x, LngCurPos.y)
If Err <> 0 Then
OldRange.Interior.ColorIndex = OldColorIndex
Else
If NewRange.Address <> OldRange.Address Then
If OldRange Is Nothing Then
Else
OldRange.Interior.ColorIndex = OldColorIndex
End If
OldColorIndex = NewRange.Interior.ColorIndex
NewRange.EntireRow.Interior.ColorIndex = 16
End If
Set OldRange = NewRange
End If
On Error GoTo 0
DoEvents
Loop
ChangeOn = False
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
For Each r In Selection.Areas
i1 = r(1).Address
i2 = r(r.Cells.Count).Address
Range(i1 & ":" & i2).EntireRow.Interior.ColorIndex = 5
Range(i1 & ":" & i2).EntireColumn.Interior.ColorIndex = 5
Next
End Sub