+ Reply to Thread
Results 1 to 13 of 13

Efficiency issue when looping through each cell

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Efficiency issue when looping through each cell

    I have a workbook with weekly data for a whole year (100.000+ records per week) that I need to compare to another workbook with 100.000 records and look for overlapping periods.
    Each record in the weekly sheet needs to be marked as checked when the comparison has been performed and if there is an overlapping period that needs to be marked as well and the record copied to a whole other sheet.

    I have done this by looping through each week checking every new record against the 100.000 records (via find), but this is quite time consuming, so I am wondering if this can’t be done more efficiently. Maybe by using matrixes?

    Any help is greatly appreciated.


    Please Login or Register  to view this content.
    Last edited by 221080; 07-31-2010 at 12:06 PM. Reason: Correct an error with a variable name in the code

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Efficiency issue when looping through each cell

    Would it be possible to filter the data using AutoFilter?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    Quote Originally Posted by royUK View Post
    Would it be possible to filter the data using AutoFilter?
    Possibly, but I do not see an immediate gain from doing that. What are you thinking?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Efficiency issue when looping through each cell

    I think someone would need to see a reasonable amount of (sanitized) data to make a useful suggestion.

    Throughout your code, you do this:
    Please Login or Register  to view this content.
    The With statement isn't doing anything. References should be like this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    Quote Originally Posted by shg View Post
    I think someone would need to see a reasonable amount of (sanitized) data to make a useful suggestion.
    I will attach sample data as soon as I can, but it is just a list of numbers on the weekly sheets, being compared to another list with numbers and a start and finish date.


    Throughout your code, you do this:
    Please Login or Register  to view this content.
    The With statement isn't doing anything. References should be like this:
    Please Login or Register  to view this content.
    It is indeed sloppy coding.
    The sheet is activated though so the code still determines the ranges, so I do not see this having any real impact on the efficiency.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Efficiency issue when looping through each cell

    AutoFilter would be much faster than a Loop

  7. #7
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    Quote Originally Posted by shg View Post
    I think someone would need to see a reasonable amount of (sanitized) data to make a useful suggestion.
    I have a small example of how the data in the different sheets look.

    Example of the data on one of the weekly sheets
    Example of data on the control sheet that each of the records on the weekly sheet is checked against.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    Quote Originally Posted by royUK View Post
    AutoFilter would be much faster than a Loop
    Could you elaborate a little on how that could be done in this example?

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Efficiency issue when looping through each cell

    The dates in your example don't make much sense.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    It is the version format. mm/dd/yyyy
    12/31/9999 indicates that there is no end date, i.e it is still running as of today.
    Last edited by shg; 07-31-2010 at 11:41 AM. Reason: deleted spurious quote

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Efficiency issue when looping through each cell

    What should be the output for the given example, and why?

  12. #12
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    If the record is on the control sheet and the dates overlap, i.e. the start date is before the monday of the week of the weekly sheet and the end date is after that monday, the record on the weekly sheet is marked as included.

    Please Login or Register  to view this content.
    and the record is then copied to a third sheet.

    Please Login or Register  to view this content.
    To check all the records and move/mark the included ones are the purpose of this piece of code.

  13. #13
    Registered User
    Join Date
    07-30-2010
    Location
    CPH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Efficiency issue when looping through each cell

    It was suggested that the fastest way was to use arrays, which I have implemented below.

    I had to loop through the registry-array as I could not find a (reasonable) way to search it and return the element number.

    So I think what I have now works and it is also a lot faster. However, it is now looping through a 100,000 elements for the registry for every record every week (100,000 records a week), which might not be the most efficient...

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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