excel中两个单元格内容相同时,输出内容,内容不同时,输出的内容包含两个单元格的所有内容,但不重复.
2个回答
展开全部
楼上的答案可以说是对的,但如果要排序,最好是使用自定义函数不完成。
自定义函数代码如下:
Function SortIf(ByVal rg1 As Range, ByVal rg2 As Range)
Dim rg As Range, rng As Range, i%, k%, s%, n%, arr()
Set rg = Range(rg1, rg2)
For Each rng In rg
For i = 1 To Len(rng)
s = Mid(rng, i, 1)
On Error GoTo l
For j = 0 To UBound(arr())
If s = arr(j) Then GoTo ll
Next
l:
ReDim Preserve arr(k)
arr(k) = s
k = k + 1
ll:
Next
Next
For i = 0 To UBound(arr()) - 1
m = i
For j = i + 1 To UBound(arr())
If arr(j) > arr(m) Then
m = j
End If
Next
If m <> i Then
n = arr(i)
arr(i) = arr(m)
arr(m) = n
End If
Next
For i = 0 To UBound(arr())
SortIf = SortIf & arr(i)
Next
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询