WORD VBA 升序排序和降序排序
这是我的代码,它将数组内的单词按升序排序。我需要帮助来更改它,以便它还可以按降序对单词进行排序,所有这些都在一个函数中。请帮忙。谢谢!
Function Sort_Asc(ByRef str() As String)
Dim iLower As Integer, iUpper As Integer, iCount As Integer, Temp As String
Dim str2 As String
iUpper = UBound(str)
iLower = 1
Dim bSorted As Boolean
bSorted = False
Do While Not bSorted
bSorted = True
For iCount = iLower To iUpper - 1
str2 = StrComp(str(iCount), str(iCount + 1), vbTextCompare)
If str2 = 1 Then
Temp = str(iCount + 1)
str(iCount + 1) = str(iCount)
str(iCount) = Temp
bSorted = False
End If
Next iCount
iUpper = iUpper - 1
Loop
End Function
Here is code I have that sorts the words inside an array into ascending order. I need help to change it in such a way that it will also sort the words in descending order, all in a single function. Please help. Thanks!
Function Sort_Asc(ByRef str() As String)
Dim iLower As Integer, iUpper As Integer, iCount As Integer, Temp As String
Dim str2 As String
iUpper = UBound(str)
iLower = 1
Dim bSorted As Boolean
bSorted = False
Do While Not bSorted
bSorted = True
For iCount = iLower To iUpper - 1
str2 = StrComp(str(iCount), str(iCount + 1), vbTextCompare)
If str2 = 1 Then
Temp = str(iCount + 1)
str(iCount + 1) = str(iCount)
str(iCount) = Temp
bSorted = False
End If
Next iCount
iUpper = iUpper - 1
Loop
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何
使用
Sort strArray, False '(False Ascending, True Descending)
调用该函数How about
and call the function using
Sort strArray, False '(False Ascending, True Descending)