Wednesday, January 13, 2016

How to Add Item to ListBox in VBA (3)



Now, we will add item from Range(A1:A1000000) to listbox

1
2
3
4
5
6
Private Sub CommandButton1_Click()

ListBox1.List = Range("A1:A1000000").Value
MsgBox "Count of items:" & ListBox1.ListCount

End Sub



Now, we will try to chek 'how fast the process is"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Private Declare Function GetTickCount Lib "Kernel32" () As Long

Private Sub CommandButton1_Click()
Dim S As Long

S = GetTickCount
    
ListBox1.List = Range("A1:A1000000").Value
MsgBox "Count of items:" & ListBox1.ListCount & vbCrLf & _
    (GetTickCount - S) / 1000 & "seconds"

End Sub

In my PC, it takes abut 2.203 seconds for 1000000 data.



Download File

Before (1)
Before (2)

No comments :

Post a Comment