- ©«¤l
- 10
- ¥DÃD
- 3
- ºëµØ
- 0
- ¿n¤À
- 11
- ÂI¦W
- 0
- §@·~¨t²Î
- windows 7
- ³nÅ骩¥»
- office 2010
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2014-4-18
- ³Ì«áµn¿ý
- 2018-9-18
|
Dear Sirs
·Q½Ð±Ð¦U¦ì¡A§Ú¤§«e¦bª¾¥G¬Ý¨ìvba¼¶¼gfunction
µ²ªG¦p¤U
https://zhuanlan.zhihu.com/p/41740899
¥¦ªºµ{¦¡¦p¤U¡A¶¶«K±N§Úªº¸ÑŪ¼¶¼g¦p¤U
Function ´£¨ú«ÂÐ(rg1 As Range, rg2 As Range)
Dim arr1, arr2
arr1 = Split(rg1, ",") '±Nªø¦ê¼Æ¾Ú1¡A«ö³r¸¹©î¤À¦¨¤@²Õ¼Æ¾Ú
arr2 = Split(rg2, ",") '±Nªø¦ê¼Æ¾Ú2¡A«ö³r¸¹©î¤À¦¨¤@²Õ¼Æ¾Ú
a = ""
For h = 0 To UBound(arr1) '³vÓ¤ñ¹ï¨â²Õ¼Æ¦r
For i = 0 To UBound(arr2)
If arr1(h) = arr2(i) Then a = a & arr2(i) & "," '±N¨â²Õ¼Æ¾Ú¬Û¦Pªº³¡¤À¯d¤U¡A¥H","¤À¹j¬Û¦P¼Æ¾Ú¡A²Õ¦¨¤@³s¦ê¦r¦ê
End If
Next
Next
Dim arr, d As Object 'ç°£结ªG¤¤ªº«ÂÐÈ
Set d = CreateObject("scripting.dictionary") '±Nd³]¬°¤@Ó¦r¨å
arr = Split(Mid(a, 1, Len(a) - 1), ",") '±Nªø¦ê¼Æ¾Úa¡A«ö³r¸¹©î¤À¦¨¤@²Õ¼Æ¾Ú¡A¶¶«K±Na¦r¦ê³Ì«á¤@Ó³r¸¹®ø°£¡C
For i = 0 To UBound(arr)
d(arr(i)) = "" '¤£ª¾¹D¬°¤°»òn±Nd(arr(i))³]¬°ªÅ¥Õ
Next i
´£¨ú«Î` = Join(d.keys, ",") '¬°¤°»ò·|¥Îd.keys¡A¬Ý¤£À´
End Function
¦A³Â·Ð¦U¦ì¤j¼w¡A·Q¤£³q¡A¤]¬d¤£¤Ó¨ì¸ê®Æ¡AÁÂÁ±z¡C |
|