VBA for Excel-如何检查范围的交点不为空
我有两个问题: 1) 如何检查交叉点或范围是否为空?例如,如果我想检查它是否为空,我就写一个例子VBA for Excel-如何检查范围的交点不为空,vba,excel,Vba,Excel,我有两个问题: 1) 如何检查交叉点或范围是否为空?例如,如果我想检查它是否为空,我就写一个例子 if application.intersect(r1,r2) is nothing 但是有什么东西是对什么都不否定的吗?例如,不是什么都不起作用 2) 我怎样才能兼容范围?例如,我有范围r1、r2、r3,我想检查r1和r2的交点是否为r3。有两件事我试过了,但没有成功: 1 - application.intersect(r1,r2) = r3 2 - application.intersect
if application.intersect(r1,r2) is nothing
但是有什么东西是对什么都不否定的吗?例如,不是什么都不起作用
2) 我怎样才能兼容范围?例如,我有范围r1、r2、r3,我想检查r1和r2的交点是否为r3。有两件事我试过了,但没有成功:
1 - application.intersect(r1,r2) = r3
2 - application.intersect(r1,r2) is r3
如果能得到任何帮助,我将不胜感激,谢谢 要查看交叉口是否为空,可以使用
If Not Application.WorksheetFunction.CountA(Application.Intersect(rng1, rng2)) > 0 Then
MsgBox "You Intersection is Empty!"
Exit Sub
End If
要查看3个范围是否相交比较困难。逻辑是这样的
如果a、b和c相交,就做点什么
Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
Set fsect = Application.Intersect(Range("rg2"), Range("rg3"))
Set gsect = Application.Intersect(Range("rg1"), Range("rg3"))
if isect = True and fsect = Tru and gsect = True then
' They all intersect each other
' Put your code here
end if
要查看两个范围的交点是否为第三个范围,请执行以下操作:
Set intRng = Intersect(R1, R2)
If Not intRng Is Nothing then
Set intRng = Intersect(intRng, R3)
If Not Intersect(intRng) Is Nothing
If intRng.Address = R3.Address Then MsgBox "intersection of ranges R1 and R2 is range R3"
End If
End If
在If:
If not应用程序之后放置not。intersect(r1,r2)为nothing