读书人

在EXCEL里写了段vb的代码出现点有关问

发布时间: 2012-12-16 12:02:32 作者: rapoo

在EXCEL里写了段vb的代码出现点问题
在EXCEL里写了段vb的代码
想实现两个区域,单击后变色,并且统计该数出现得次数
现在问题是除了两个区域以外,其他单元格一单击都变成蓝色

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.Intersect(Target, [B1:AH43]) Is Nothing Or Target.Count > 1 Then
Application.EnableEvents = False
Target.Interior.Color = RGB(0, 0, 255) '填充蓝色
Cells(44, Target.Column) = Cells(44, Target.Column).Value + 1
Application.EnableEvents = True
ElseIf Application.Intersect(Target, [AI1:AX43]) Is Nothing Or Target.Count > 1 Then
Application.EnableEvents = False
Target.Interior.Color = RGB(255, 0, 0) '填充红色
Cells(44, Target.Column) = Cells(44, Target.Column).Value + 1
Application.EnableEvents = True
End If
End Sub

[最优解释]
用if判断两次嘛

if 不在这个区域
exit sub
else
if 在A区域
变蓝色
else 在B区域
变红色
end if
end if

[其他解释]
If Application.Intersect(Target, [B1:AH43]) Is Nothing Or Target.Count > 1 Then

如果不在这个区域,这个判断肯定为真啊,那就肯定变蓝了
[其他解释]
Intersect A is nothing And Intersect B is nothing
[其他解释]
HELP ME
[其他解释]

引用:
If Application.Intersect(Target, [B1:AH43]) Is Nothing Or Target.Count > 1 Then

如果不在这个区域,这个判断肯定为真啊,那就肯定变蓝了

其他区域不想变色怎么改啊
[其他解释]
引用:
用if判断两次嘛

if 不在这个区域
exit sub
else
if 在A区域
变蓝色
else 在B区域
变红色
end if
end if


不在这个区域。。这怎么写啊

读书人网 >OFFICE教程

热点推荐