+ Reply to Thread
Results 1 to 15 of 15

Very s l o w looping

  1. #1
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Very s l o w looping

    In a workbook (Vat Current) I have 5 worksheets, Summary, 1st Quarter Nov-Jan, 2nd Quarter Feb-April, 3rd Quarter May-July and 4th Quarter Aug-Oct. There is one table on each of the worksheets, FirsQ, SecondQ, ThirdQ and FourthQ with a total number of records around 1200.

    On the summary sheet I have a list of Suppliers starting at cell AW19 and going down to AW420 (this will grow)
    I need to take each supplier, then loop through each of the tables (FirsQ, SecondQ, ThirdQ and FourthQ) and count how many entries there are and write that number in column AX adjacent to the Suppliers name.

    I have written some looping code that does work (sometimes) but it can take 15 minutes and looking in Task Manager, Excel is using in excess of 4Gb memory while executing.

    If it completes the task, no other code can be run unless I restart Excel.

    Sometimes it never completes and I have to End Task.

    I know I am looking at around 400 suppliers x around 1200 records = around 480,000 items, but should it take this long? Is there a better more efficient way to do this?
    Please Login or Register  to view this content.


    Sorry, because of the amount of data with confidential information (names, addresses and costs) I am unable to attach the workbook.

    Thanks for looking,
    Keith

  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
    28,185

    Re: Very s l o w looping

    without a file, it will not be possible to test your code and changes to it. A small file of 2-30 rows will normally suffice with (obviously!) any confidential data removed.
    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 Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Very s l o w looping

    Hi John thanks for your interest.
    Attached is a very much thinned out workbook, I have left only data required for the count and I have removed most of the columns on each sheet.

    Even with this much reduced workbook, when I clicked the button Excel was using around 4 gig of memory and 40% of my cpu.
    Attached Files Attached Files

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Very s l o w looping

    Hey kjg,

    In AW19 put this formula!

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    BTW - you have lots of blank rows on your monthly list(s).
    If your lists grow on the non-summary sheets we can make the above formula more generalized.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Very s l o w looping

    Hi John,

    The blank rows are my fault as I removed lots of records but forgot to remove the blanks.
    The formula just replaced the list I already have, it didn’t enter the number of entries from all the quarterly sheets.
    The list as well as the 4 quarterly sheets will all get larger over time.

    Kind Regards,
    Keith

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Very s l o w looping

    Hi Keith,

    I'm Marv, not John because he is smarter than me.

    Try this in A5 of your Summary sheet. NO VBA needed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Very s l o w looping

    Hi Marv thank you also for your interest and time.

    Again, this just recreates the list I already have but dose not put the number of transactions in the next column!

    Kind Regards,
    Keith

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Very s l o w looping

    Hello. Try this, please:

    PHP Code: 
    Sub No_Of_Payments()
    Dim aQ&, i&, Dhj%

    Range("Summary!AW18").CurrentRegion.ValueUBound(a)
    Set D CreateObject("Scripting.Dictionary")
    For 
    2 To QD(a(i1)) = 0Next

    For hj Sheets("Summary").Index To Worksheets.Count
      a 
    Sheets(hj).Range("F4"Sheets(hj).Cells(Rows.Count"F").End(xlUp)).ValueUBound(a)
      For 
    1 To Q
        
    If a(i1) <> "" Then D(a(i1)) = D(a(i1)) + 1
      Next
    Next

    D.Count
    With Sheets
    ("Summary").Range("aw18:ax18")
      .
    Offset(1).Resize(Q).Delete xlShiftUp
      
    .Cells(21).Resize(Q) = Application.Transpose(D.keys)
      .
    Cells(22).Resize(Q) = Application.Transpose(D.items)
      .
    Resize(Q).Sort .Cells(1), 1Header:=xlYes
      Application
    .Goto .Parent.Range("au16"), True
    End With

    = Empty: = Empty: MsgBox "End."

    End Sub 
    Attached Files Attached Files
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Very s l o w looping

    Hi kjg,

    You are a tough one to please. See the attached with no VBA, that has what you wanted on the Summary sheet down at row 20.
    Vat Current kjg Answer with Counts.xlsm

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Very s l o w looping

    here's a vba loop:
    Please Login or Register  to view this content.
    Ben Van Johnson

  11. #11
    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
    28,185

    Re: Very s l o w looping

    No VBA .....

    in AX2 of "Summary"

    =SUMPRODUCT(COUNTIF(INDIRECT("'"&Sheets&"'!F:F"),$AW19))

    Copy down

    "Sheets" is named range of your tab names i.e 1st Quarter Nov-Jan, 2nd Quarter Feb-April, 3rd Quarter May-July, 4th Quarter Aug-Oct
    Last edited by JohnTopley; 11-25-2022 at 02:30 AM.

  12. #12
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Very s l o w looping

    Hi Guys,
    I would like to thank you all for your patients with me and my request for help, it always amazes me how many people are willing to help others.

    It also amazes me how many ways there are to achieve the results required, most of which I don’t fully understand.

    I woke up this morning with 4 potential solutions, I have tried all 4 and each gives me what I require, but I think I will be using the solution that protonLeah supplied as it is more inline with what I am doing before and after I get the results.

    Thank you all,
    Keith

  13. #13
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Very s l o w looping

    Quote Originally Posted by kjg View Post
    ... I woke up this morning with 4 potential solutions, I have tried all 4 and each gives me what I require...
    The solution I have given you discovers 8 payees that were not on the original list. So not all solutions are equal...

  14. #14
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Very s l o w looping

    Thank you for this observation.

    As the Payees list and each quarter was edited to remove individual names, some were overlooked, this is why you found some extra in one place and not in another.

    Kind Regards,
    Keith

  15. #15
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Very s l o w looping

    The solution I presented to you is part of the original list (like all alternative solutions).
    But since the macro then goes through its Payees lists -sheet by sheet-, it ends up obtaining the new ones (if there are any).
    If you had requested an update of Payees, then the original list would not have to be taken into account and it would be enough to see what you have on your 4 sheets.

+ 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. Do Until Looping (not looping through all other columns)
    By orle8050 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:37 AM
  2. Looping through row
    By dirtydan86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-03-2012, 10:53 AM
  3. [SOLVED] vba looping
    By amu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-24-2012, 01:25 PM
  4. [SOLVED] VBA Looping with Ifs
    By harrison298 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2012, 04:35 AM
  5. vba looping
    By amu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2012, 03:36 AM
  6. Help with looping
    By sisqo48167 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-04-2011, 02:06 PM
  7. Help with looping
    By enhydra in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-04-2011, 11:13 AM
  8. Looping I think??
    By jimmyquinn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2007, 08:24 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