请问下面的VBA可以改成能够处理 形式为f(x,y,z,w)

请问下面的VBA可以改成能够处理 形式为f(x,y,z,w)
Function f(x,y)
Dim dic As Object
Set dic = CreateObject("Scripting.Dictionary")
x = Replace(x,",",",")
y = Replace(y,",",",")
a = Split(x,",")
b = Split(y,",")
For i = 0 To UBound(a) - 1
dic(a(i)) = ""
Next i
For i = 0 To UBound(b) - 1
If dic.exists(b(i)) Then f = f & b(i) & ","
Next i
Set dic = Nothing
End Function
玉玉133 1年前 已收到3个回答 举报

可乐人 幼苗

共回答了17个问题采纳率:88.2% 举报

不固定参数,使用方法:
=f(a1,a2,a3)
-----------------
Function f(ParamArray x() As Variant)
'求多个单元格数据的交集
'单元格内容格式:1,23,5,26,14
Application.Volatile
Dim d1,d2,iKeys,i,j,k,a()
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
ReDim a(LBound(x) To UBound(x))
For i = LBound(x) To UBound(x)
x(i) = Trim(Replace(x(i),","," "))
a(i) = Split(x(i)," ")
Next
i = LBound(a)
For j = LBound(a(i)) To UBound(a(i))
d1(a(i)(j)) = a(i)(j)
Next j
For i = LBound(a) + 1 To UBound(a)
If d1.Count < 1 Then
f = ""
GoTo 100
Else
iKeys = d1.keys
End If
For j = LBound(a(i)) To UBound(a(i))
d2(a(i)(j)) = a(i)(j)
Next j
For j = LBound(iKeys) To UBound(iKeys)
If Not d2.Exists(iKeys(j)) Then d1.Remove (iKeys(j))
Next j
d2.RemoveAll
Next i
If d1.Count < 1 Then
f = ""
GoTo 100
Else
iKeys = d1.keys
f = Join(iKeys,",")
End If
Exit Function
100:
Set d1 = Nothing
Set d2 = Nothing
End Function

1年前

1

8w1jh34 幼苗

共回答了1个问题 举报

可以,你运行宏 aaa试试,有4个参数。
Sub aaa()
x = "a,b,c,one,three,two"
y = "b,one,two,three,four"
z = "two,four,five,b"
w = "three,four,ten,b,two"
Range("A1") = f(x, y, z, w)
End Sub

1年前

2

刘宝山222 幼苗

共回答了45个问题 举报

Function fd(xa, ParamArray ya())
Dim dic As Object, x, y, a, b, i%
Set dic = CreateObject("Scripting.Dictionary")
x = xa
For Each y In ya
x = Replace(x, ",", ",")
y = Replace...

1年前

1
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 19 q. 0.388 s. - webmaster@yulucn.com