Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excelvba交集_Vba_Excel_Intersect - Fatal编程技术网

excelvba交集

excelvba交集,vba,excel,intersect,Vba,Excel,Intersect,我在网上找到了这段代码,显然它对其他人有效,但对我无效?我不知道哪里不对。我举了一个简单的例子,将我的Range1和Range2设置为excel中的某些单元格 另外,我想知道是否有办法返回十字路口,如果可以的话。提前谢谢 Function InRange(Range1 As Range, Range2 As Range) As Boolean Set intersectRange = Application.Intersect(Range1, Range2) If interse

我在网上找到了这段代码,显然它对其他人有效,但对我无效?我不知道哪里不对。我举了一个简单的例子,将我的Range1和Range2设置为excel中的某些单元格

另外,我想知道是否有办法返回十字路口,如果可以的话。提前谢谢

Function InRange(Range1 As Range, Range2 As Range) As Boolean
    Set intersectRange = Application.Intersect(Range1, Range2)
    If intersectRange Is Nothing Then
        InRange = False
    Else
        InRange = True
    End If
End Function

在我看来,您希望Intersect检查两个区域是否有具有相同值的单元格?这是S15和T15中的值“a”的起点吗

如果是这样,那么这就是为什么你没有得到你所期望的。Intersect函数返回两个范围的“重叠”范围,而不管每个范围内的值如何


由于这是我在SE上的第一篇文章,我希望这能有所帮助:)

您的函数没有根本性的错误,但我会将intersectRange变量声明为一个范围。如果要返回intersect范围,可以直接从intersectRange is not nothing返回变量,并从函数返回变量

Function InRange(Range1 As Range, Range2 As Range) As Variant
    Dim intersectRange As Range
    Set intersectRange = Application.Intersect(Range1, Range2)
    If intersectRange Is Nothing Then
        InRange = False
    Else
        InRange = intersectRange.Address(0, 0)
    End If
End Function

有关的详细信息。

使用此代码,您到底想实现什么,以及您目前得到的结果是什么?你能创建一个子函数来调用这个函数,然后一步一步地通过这个函数来查看它在做什么吗?@TMH8885,我希望是真的,但得到了假的。你是对的,愚蠢的我,我希望它能像Matlab函数intersect一样工作,它会给你“重叠”。明白了,谢谢。接得好;我完全没有注意到这个词的滥用。