apolloh斑竹,为什么我最下面的代码运行正常,而在自定义函数中却不行呢?我看了好久都没找到原因 能帮我看看吗?(我知道你们在这里讨论函数的方法,不好意思,打扰了) Function Hre(rng As Range, rng1 As Range, n)
Application.Volatile
Dim Arr With rng
For i = 1 To .Count
Set c = rng1.Find(.Cells(i), LookAt:=xlWhole)
If Not c Is Nothing Then
.Cells(i).Value = .Cells(i) & "-----"
c.Value = c.Value & "-----"
End If
Next
End With
k = 1
Set rng2 = Application.Union(rng, rng1)
For Each r In rng2
If InStr(1, r, "-----") = 0 Then
ReDim Arr(k)
Arr(k) = r.Value
k = k + 1
End If
Next
rng2.Replace "-----", "", LookAt:=xlPart Hre = Arr(n)
End Function ---------------------------------------------------- Sub hjs() Set rng = Sheet1.Range("b3:b18")
Set rng1 = Sheet1.Range("d3:d14") With rng
For i = 1 To .Count
Set c = rng1.Find(.Cells(i), LookAt:=xlWhole)
If Not c Is Nothing Then
.Cells(i).Value = .Cells(i) & "-----"
c.Value = c.Value & "-----"
End If
Next
End With Set rng2 = Application.Union(rng, rng1)
k = 3
For Each r In rng2
If InStr(1, r, "-----") = 0 Then
Sheet1.Cells(k, 6) = r
k = k + 1
End If
Next
rng2.Replace "-----", "", LookAt:=xlPart End Sub |