+ Reply to Thread
Results 1 to 7 of 7

Is there a way to optimize this loop?

  1. #1
    Registered User
    Join Date
    09-19-2024
    Location
    Houston, USA
    MS-Off Ver
    365 Business
    Posts
    3

    Lightbulb Is there a way to optimize this loop?

    Hello all, im pretty new to programming in VBA, and I was able to create a 3 layer loop, to populate cells from one column, using different cells from rows and cells. since I have a to populate around 1100 cells, mixing a set of say (89 rows of data) with 22 different preffixes.... I created the loop and it worked, but it is taking around 3 minutes to complete the population of 1100 cells... Im adding the script and also the result of what it should be.
    Please Login or Register  to view this content.
    This is the result: As you can see left three columns are being joined with the data column.
    Attached Images Attached Images
    Last edited by 6StringJazzer; 09-19-2024 at 11:42 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,953

    Re: Is there a way to optimize this loop?

    Try

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,110

    Re: Is there a way to optimize this loop?

    Another way:
    Please Login or Register  to view this content.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,001

    Re: Is there a way to optimize this loop?

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however we recommend that you include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Guideline #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here.

    I have done it for you since it's your first post.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    09-19-2024
    Location
    Houston, USA
    MS-Off Ver
    365 Business
    Posts
    3

    Re: Is there a way to optimize this loop?

    Thanks very much!

  6. #6
    Registered User
    Join Date
    09-19-2024
    Location
    Houston, USA
    MS-Off Ver
    365 Business
    Posts
    3

    Re: Is there a way to optimize this loop?

    It worked! thank you very much! that is impressive! I am assuming that all of the values are stored in "a" , and then they are transposed at the end in the cell G5, for the ReDim i cant make something out of it for now

  7. #7
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,110

    Re: Is there a way to optimize this loop?

    "ReDim" = re-dimension. It's necessary to increase the capacity of the array so that it can accommodate another element.
    They "Preserve" keyword prevents what's already in the array from being lost.
    Last edited by ByteMarks; 09-19-2024 at 12:02 PM.

+ 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. Optimize Macro- creating binary matrix out of data information- nested loop
    By simz92 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-06-2017, 04:15 AM
  2. [SOLVED] Almost 6,000 lines ... I need help to loop or optimize
    By calebjcook in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-08-2015, 09:22 AM
  3. VBA For loop, optimize speed and performance
    By britzer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-04-2014, 08:56 AM
  4. Is there any way to optimize this FOR loop?
    By lxsscott in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-23-2013, 03:50 PM
  5. Optimize for loop in order to win time
    By DamienR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2013, 11:39 PM
  6. Optimize copy/paste loop
    By aldsv in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-09-2005, 06:07 AM
  7. [SOLVED] Optimize VBA Excel 2003 NextFor loop
    By eric_rutt@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2005, 09:06 AM

Tags for this Thread

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