EXCEL 如何将某一区域内的一堆数字 罗列出来按顺序排列,重复的就只选一个比如:
3个回答
展开全部
可用VBA来做。假定原始数据在A1:F6,结果存放在H1:M6,可用如下VBA程序来做:
Sub temp()
Dim arr, brr, i As Integer, j As Integer, i1 As Integer, j1 As Integer
Dim exit_condition As Boolean
exit_condition = False
arr = [a1:f6]
[h1:m6].ClearContents
brr = [h1:m6]
For i = 1 To 6
For j = 1 To 6
brr(i, j) = Application.WorksheetFunction.Min(arr)
For i1 = 1 To 6
For j1 = 1 To 6
If arr(i1, j1) = brr(i, j) Then
arr(i1, j1) = Application.WorksheetFunction.Max(arr)
End If
Next j1
Next i1
exit_condition = brr(i, j) = Application.WorksheetFunction.Max(arr)
If exit_condition Then
Exit For
End If
Next j
If exit_condition Then
Exit For
End If
Next i
[h1:m6] = brr
End Sub
Sub temp()
Dim arr, brr, i As Integer, j As Integer, i1 As Integer, j1 As Integer
Dim exit_condition As Boolean
exit_condition = False
arr = [a1:f6]
[h1:m6].ClearContents
brr = [h1:m6]
For i = 1 To 6
For j = 1 To 6
brr(i, j) = Application.WorksheetFunction.Min(arr)
For i1 = 1 To 6
For j1 = 1 To 6
If arr(i1, j1) = brr(i, j) Then
arr(i1, j1) = Application.WorksheetFunction.Max(arr)
End If
Next j1
Next i1
exit_condition = brr(i, j) = Application.WorksheetFunction.Max(arr)
If exit_condition Then
Exit For
End If
Next j
If exit_condition Then
Exit For
End If
Next i
[h1:m6] = brr
End Sub
更多追问追答
追问
我按照这样弄,可结果并未输出是啥回事?
追答
我运行过,结果正确。这里不可传文件,给个Email地址或QQ号。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询