manthanein 发表于 2020-12-24 00:59:26

excel怎么取两个正整数集的交集和并集

集合A是不小于a且不大于b的正整数集。
集合B是不小于c且不大于d的正整数集。
abcd已知,如何用excel取A并B、A交B呢?
我一开始是用countif做的,数据一大就有点麻烦。

manthanein 发表于 2020-12-24 00:59:53

主要是求A交B、A并B的元素个数。

ShuXueZhenMiHu 发表于 2020-12-24 03:29:41

用VBA来做,沥遍A中的所有元素,看它是否在B中。

mathematica 发表于 2020-12-24 10:22:40

ShuXueZhenMiHu 发表于 2020-12-24 03:29
用VBA来做,沥遍A中的所有元素,看它是否在B中。

python试试看,先从Excel读取数据,处理后,再返回Excel

northwolves 发表于 2020-12-24 11:43:35

Index=0, 交集
Index=1,并集
Function AB(a&, b&, c&, d&, index&)
Dim r As Range
If index = 0 Then Set r = Intersect(Range(Rows(a), Rows(b)), Range(Rows(c), Rows(d)))
If index = 1 Then Set r = Union(Range(Rows(a), Rows(b)), Range(Rows(c), Rows(d)))
If Not r Is Nothing Then
AB = "{" & Replace(r.Address, "$", "") & "}"
Else
AB = "{}"
End If
End Function

Sub Test()
Debug.Print AB(3, 20, 17, 28, 0)
Debug.Print AB(3, 20, 17, 28, 1)
End Sub

页: [1]
查看完整版本: excel怎么取两个正整数集的交集和并集