相关文章推荐
坏坏的海龟  ·  VBA) (Property Let ...·  1 月前    · 
狂野的皮蛋  ·  怎么继承 CSSProperties ...·  6 月前    · 
酒量大的拐杖  ·  Java ...·  1 年前    · 

excel vba sort listbox by date

在Excel VBA中,如果您想要将ListBox控件按日期排序,您可以使用以下代码来实现:

Private Sub CommandButton1_Click()
  Dim i As Long
  Dim temp As Variant
  Dim j As Long
  For i = 0 To ListBox1.ListCount - 2
    For j = i + 1 To ListBox1.ListCount - 1
      If CDate(ListBox1.List(i)) > CDate(ListBox1.List(j)) Then
        temp = ListBox1.List(i)
        ListBox1.List(i) = ListBox1.List(j)
        ListBox1.List(j) = temp
      End If
    Next j
  Next i
End Sub

该代码通过使用冒泡排序算法对ListBox中的项进行排序。您可以通过将代码粘贴到模块中并运行它来执行排序。

  •