
小序体育游戏app平台
列表框(ListBox)是最常用的VBA窗体控件之一。结束列表框项指标上移下移功能,不错达到自界说排序的成果。
UI谋略
这里主要使用到了一个列表框和两个按钮控件,主界面谋略和关系控件定名如下所示。
VBA结束代码
1.窗体运鼎新事件
Private Sub UserForm_Initialize() ListBox1.AddItem "张三" ListBox1.AddItem "李四" ListBox1.AddItem "王五" ListBox1.AddItem "赵六" ListBox1.AddItem "孙七" ListBox1.AddItem "周八" ListBox1.AddItem "吴九" ListBox1.AddItem "郑十"End Sub
2.上移按钮单击事件
Private Sub cmdbUp_Click() Dim i As Integer ' 确保ListBox有选中的模样 If ListBox1.ListIndex <> -1 Then ' 遍历列表框的模样 For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) And i <> 0 Then temp = ListBox1.List(i) ListBox1.List(i) = ListBox1.List(i - 1) ListBox1.List(i - 1) = temp '保执列表框选中的模样不变 ListBox1.Selected(i - 1) = True Exit For End If Next i End IfEnd Sub
3.下移按钮单击事件
Private Sub cmdbDown_Click() Dim i As Integer ' 确保ListBox有选中的模样 If ListBox1.ListIndex <> -1 Then ' 遍历列表框的模样 For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) And i <> ListBox1.ListCount - 1 Then tempp = ListBox1.List(i) ListBox1.List(i) = ListBox1.List(i + 1) ListBox1.List(i + 1) = tempp '保执列表框选中的模样不变 ListBox1.Selected(i + 1) = True Exit For End If Next i End IfEnd Sub
保举阅读
基于Excel VBA谋略的抽奖系统哄骗VBA操作Excel称号处置器哄骗VBA一键将多个单位格转为复选框
念念了解更多精彩骨子体育游戏app平台,快来温文VBAMatrix
