以下是引用gusuitang在2007-11-15 13:44:10的发言:楼主,能写个自定义函数,也是查找一对多值的,例如:a 对应1 、2、3,该函数能将1.2.3都能找出来。 有办法吗? Function getit(ByVal s As String) Dim d As Object, b(), i As Long, j As Long, n As Long Set d = CreateObject("scripting.dictionary") For i = 1 To 20 n = Int(Rnd * 20 + 1) ReDim b(1 To n) For j = 1 To n b(j) = j Next d.Add Chr(i + 96), b Next If d.exists(s) Then getit = d(s) Set d = Nothing End Function Sub macro1() Dim i As Byte For i = 1 To 10 Debug.Print Chr(i + 96); vbTab; Join(getit(Chr(i + 96)), ",") Next End Sub 返回: a 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 b 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 c 1,2,3,4,5,6,7,8,9,10,11,12,13,14 d 1,2,3,4,5,6,7 e 1 f 1,2,3,4,5,6,7,8,9,10,11,12,13 g 1,2,3,4,5,6,7,8,9,10,11,12,13,14 h 1,2,3,4 i 1,2,3,4,5 j 1,2,3,4,5,6,7 |