谢谢 Long_III 我采用你所说的第二种方式,可以改为函数使用,如下, Function jc(r1 As String) Dim i%, iMax%, k%, m Dim arr1, arr2, arr() As String arr1 = Array("", "吖", "八", "嚓", "咑", "鵽", "发", "猤", "铪", "夻", "咔", "垃", "嘸", "旀", "噢", "妑", "七", "囕", "仨", "他", "屲", "夕", "丫", "帀") arr2 = Array("", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z") For k = 1 To Len(r1) m = Mid(r1, k, 1) ReDim Preserve arr(1 To k) '定义动态数组大小 arr(k) = arr2(Application.WorksheetFunction.Match(m, arr1, 1) - 1) '用match函数的近似查找 Next jc = Join(arr, "") End Function 但第一种改为函数时,却不行,不知道什么地方不对,请老师看看! Function jc(r1 As Range) Dim i%, iMax%, k% Dim arr() Dim arr1, arr2, arr3 Dim m As String arr1 = Array("", "吖", "八", "嚓", "咑", "鵽", "发", "猤", "铪", "夻", "咔", "垃", "嘸", "旀", "噢", "妑", "七", "囕", "仨", "他", "屲", "夕", "丫", "帀") arr2 = Array("", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z") iMax = UBound(arr1) ReDim arr(0 To iMax, 0 To 1) '重新定义一个二维数组 For i = 0 To iMax arr(i, 0) = arr1(i) arr(i, 1) = arr2(i) Next For k = 1 To Len(r1) m = Mid(r1, k, 1) ReDim Preserve arr(1 To k) '定义动态数组大小 arr(k) = Application.WorksheetFunction.VLookup(m, arr, 2) Next k jc = Join(arr(), "") End Function
|