Results 1 to 25 of 25

Improve code using ADODB.Recordset when populate data in listbox to make fast

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-25-2022
    Location
    Libya
    MS-Off Ver
    2019
    Posts
    120

    Improve code using ADODB.Recordset when populate data in listbox to make fast

    Hi,
    this is part of my project I face really slowness in the code when add about 30 sheets and 5000 rows for each sheet.
    the code will exclude row contains OPENING word in column C and row contains TOTAL word in column A for each sheet..
    here is code
    Sub LoadData()
    
        Dim s$(1), x, e, ar()
        Dim arr() As Variant, n As Long, ymd As Long
        Dim yy As Long, mm As Long, dd As Long
        
        For Each e In Array("Mussala", "mssau", "mjhgsg")
            s(0) = s(0) & IIf(s(0) = "", "", "Union All (") & "Select " & _
            "Format(`DATE`,'dd/mm/yyyy'), `INVOICE NO`, `TYPE`, `DEBIT`, `CREDIT`, " & _
            "`BALANCE` From `" & e & "$` Where `TYPE` <> 'OPENING' And `TYPE` Is Not Null " & IIf(s(0) = "", "", ") ")
        Next
        s(1) = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & _
             ";Extended Properties='Excel 12.0;HDR=Yes';"
        With CreateObject("ADODB.Recordset")
            .Open s(0), s(1), 3, 3, 1
            x = .GetRows
        End With
        
        
        For i = 0 To UBound(x, 2)
            
            yy = --(Right(x(0, i), 4)): mm = --(Mid(x(0, i), 4, 2)): dd = --(Left(x(0, i), 2))
            ymd = DateSerial(yy, mm, dd)
            If ymd >= Sdate And ymd <= fDate Then
                n = n + 1
                ReDim Preserve ar(0 To 5, 1 To n)
                For j = 0 To UBound(x, 1)
                    ar(j, n) = x(j, i)
                Next j
            End If
        Next i
        
        With Me.ListBox1
            .ColumnCount = UBound(ar, 1) + 1
            .Column = ar
            For i = 0 To .ListCount - 1
               .List(i, 3) = Format(.List(i, 3), "#,##0.00")
               .List(i, 4) = Format(.List(i, 4), "#,##0.00")
               .List(i, 5) = Format(.List(i, 4), "#,##0.00")
            Next i
        End With
    is there any chance to improve or alternative to make fast,please?
    Attached Files Attached Files
    Last edited by Mussala; 02-13-2025 at 11:18 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Improve speed to populate Listbox based on a Textbox entry
    By mamaexcel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-07-2018, 04:50 AM
  2. How to make this code work Fast - while handling more data
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2017, 07:18 PM
  3. Replies: 0
    Last Post: 08-26-2016, 06:08 AM
  4. Change ADODB.Recordset by New
    By Remphan in forum Access Tables & Databases
    Replies: 1
    Last Post: 03-13-2016, 07:51 PM
  5. ADODB Recordset Retrieving Data from a SharePoint Excel File
    By Bradleybww in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-19-2015, 08:59 PM
  6. excel vba populate listbox from mysql recordset
    By rodriguez76 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2013, 02:24 PM
  7. Populate VBA Userform Listbox using SQL Recordset
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2013, 06:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1