|
楼主 |
发表于 2018-9-12 17:51
|
显示全部楼层
谢谢版主了,可以看下以下代码
Private Sub Worksheet_SelectionChange(ByVal targe As Range)
If Application.Union(Range("Table1"), ActiveCell).Address <> Range("Table1").Address Then
Exit Sub
End If
Cells.Interior.ColorIndex = xlNone
Dim i
Dim j
i = Range("Table1").Address(False, False)
j = VBA.Left(i, 1)
k = VBA.Mid(i, 4, 1)
Dim m
Dim n
m = ActiveCell.Address(False, False)
n = VBA.Left(m, 1)
Select Case n
Case Is = j
Range(ActiveCell, ActiveCell.End(xlToRight)).Interior.ColorIndex = 35
Case Is = k
Range(ActiveCell.End(xlToLeft), ActiveCell).Interior.ColorIndex = 35
Case Else
Range(ActiveCell.End(xlToLeft), ActiveCell.End(xlToRight)).Interior.ColorIndex = 35
End Select
End Sub
但是还有以下问题
1. 如果从表跳出去后,最后颜色会留在表内
2. 本来截取自定义字段,但是好像和函数截取方法完全不一样,比如K的取值,一旦Address地址范围3位数后4位数就会错误,是否可以帮忙改下可变长度自取,其实就是:后第一个字符
谢谢大家的帮忙 |
|