excel - 使用冒泡方法的列表框排序跳过列表框中的第一项
问题描述
我需要帮助自定义此冒泡排序代码,以便它跳过列表框中的第一项,仅对列表框中的其余项目进行排序。我迷路了,需要一些指示。谢谢
Dim j As Long
Dim sTemp As String
Dim sTemp2 As String
Dim LbList As Variant
'Store the list in an array for sorting
LbList = Me.WorksheetListBox.List
'Bubble sort the array on the first value
For i = LBound(LbList, 1) To UBound(LbList, 1) - 1
For j = i + 1 To UBound(LbList, 1)
If LbList(i, 0) > LbList(j, 0) Then
'Swap the first value
sTemp = LbList(i, 0)
LbList(i, 0) = LbList(j, 0)
LbList(j, 0) = sTemp
'Swap the second value
sTemp2 = LbList(i, 1)
LbList(i, 1) = LbList(j, 1)
LbList(j, 1) = sTemp2
End If
Next j
Next i
'Remove the contents of the listbox
Me.WorksheetListBox.Clear
'Repopulate with the sorted list
Me.WorksheetListBox.List = LbList
解决方案
推荐阅读
- nativescript - iOS webview拒绝连接但Android工作正常
- javascript - 未处理的拒绝(TypeError):尝试在 ReactJS 上使用 Axios 加载 API 数据时无法读取未定义发生的属性“0”
- c# - 为什么编译错误“使用未分配的局部变量”?
- c# - 使用 EF Core Linq2Sql 聚合聚合
- html - 元素聚焦时如何动态更改 sass 属性?
- html - 如何在 VBA 中获取网站页面的标题?
- push-notification - 每个用户的浏览器推送通知
- windows - 在 Windows 上以编程方式按下游戏控制器按钮
- excel - 如何编码我的用户窗体以在所选单元格下方插入指定数量的行?
- javascript - 仅当字符串与数据匹配时如何发送请求