+ Reply to Thread
Results 1 to 25 of 25

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

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

    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
    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    270

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

    Nie podoba mi się Redim Preserve w pętli FOR.
    1. Usuń Redim Preserve w pętli FOR
    2. Przed For i = 0 i po Next i dodaj po 1 linię
    3. Poprawiony kod
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    If all data is in order, then no need to loop all rows...
    Find Start Date and then End Date and only loop those rows populating to Array
    Also...No need for listbox formatting loop...do that in the first loop...
    Last edited by Sintek; 02-14-2025 at 09:11 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

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

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

    @hungt
    I don't understand your comment , sorry !

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

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

    Also...No need for listbox formatting loop...do that in the first loop...
    I don't think this could be main reason to do that.
    even if I delete this part will continue same problem!

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    Please Login or Register  to view this content.

    If all data is in order, then no need to loop all rows...
    Find Start Date and then End Date and only loop those rows populating to Array

    If above is true then can make it faster...
    Last edited by Sintek; 02-15-2025 at 04:47 AM. Reason: Amended Code based on OP comment...

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

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

    this is really better sintek .
    but should also be without writing dates in textboxes.

  8. #8
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    270

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

    Quote Originally Posted by Mussala View Post
    @hungt
    I don't understand your comment , sorry !
    The point is not to Redim PRESERVE in the FOR loop. I gave a different code. Did you check my code?

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

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

    The point is not to Redim PRESERVE in the FOR loop. I gave a different code. Did you check my code?
    Mismatch error
    Please Login or Register  to view this content.

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    but should also be without writing dates in textboxes.
    See amended post 6 above...

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

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

    subscript out of range
    Please Login or Register  to view this content.
    by the way I would loop through sheets just before FRM sheet , not all of sheets except FRM sheet as your code does it.

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    by the way I would loop through sheets just before FRM sheet , not all of sheets except FRM sheet as your code does it.
    So why not upload a sample file representing your actual file so no time is wasted again...
    Error is due to these other sheets not presenting same data setup...

  13. #13
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,281

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

    Mussala,
    If you are using SQL to fetch data, then add a dates filter to it as well, so you don't have to filter them in the "For...Next" loop, it will be faster.
    In your case, to keep it simple (and what you are already used to), the simplest modification to the SQL query is, e.g.:
    Please Login or Register  to view this content.

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

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

    So why not upload a sample file representing your actual file so no time is wasted again...
    Error is due to these other sheets not presenting same data setup...
    just I copy random data to show how work for many data.
    Attached Files Attached Files

  15. #15
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    The above is exactly same as other...
    3 tabs and FRM???

    Code errors cause of this...
    Please Login or Register  to view this content.
    Change 10000 to bigger amount...

    by the way I would loop through sheets just before FRM sheet
    Please Login or Register  to view this content.
    Last edited by Sintek; 02-15-2025 at 09:35 AM.

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

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

    The above is exactly same as other...
    3 tabs and FRM???
    yes but I said
    when add about 30 sheets and 5000 rows for each sheet.
    Change 10000 to bigger amount...100000
    it's fixed.
    can check this comment, please?
    by the way I would loop through sheets just before FRM sheet , not all of sheets except FRM sheet as your code does it.

  17. #17
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    can check this comment, please?
    See code above in post 15...Have amended...

  18. #18
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    270

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

    Quote Originally Posted by Mussala View Post
    Mismatch error
    Please Login or Register  to view this content.
    You complained that the code was slow, so I suggested moving Redim outside the FOR loop. I didn't check the correctness of the code because you didn't complain about the error. The quoted line is your code, I didn't suggest it. For me EOT.

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

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

    I add new sheet after FRM sheet and show mismatch error
    Please Login or Register  to view this content.

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

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

    You complained that the code was slow
    yes
    so I suggested moving Redim outside the FOR loop
    maybe this reason causes error.
    I didn't check the correctness of the code because you didn't complain about the error
    no need to check i because the original code works without any error.

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

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

    If you are using SQL to fetch data, then add a dates filter to it as well, so you don't have to filter them in the "For...Next" loop, it will be faster.
    thanks for advice, but truly I don't use SQL and I don't know how link with SQL despite of I hear of that.

  22. #22
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    Please Login or Register  to view this content.
    amended above...

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

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

    thank you so much, sintek.

  24. #24
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

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

    Glad you got it sorted...tx for rep +

  25. #25
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,281

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

    Quote Originally Posted by Mussala View Post
    ... but truly I don't use SQL...
    Did you write the topic title and content of the first post yourself or did someone write it for you ?

+ Reply to Thread

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