+ Reply to Thread
Results 1 to 13 of 13

Do While Loop never stops

  1. #1
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Do While Loop never stops

    Dear Sirs,

    I just come up with a problem that the vba runs the loop but will never end. The codes previously work correctly but seems fails after I made some slight changes to the codes and folder file names or whatever which I cannot remember :

    Files in folder :

    11038-CAL-201906.xls
    11041-CAL-201906.xls

    Please Login or Register  to view this content.

    Would like if someone could help spotting out where the error is ?

    Many thanks !

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question

    Hi !

    Too many things to say but first we wanna know where this code is located, which kind of module ?

  3. #3
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Do While Loop never stops

    The codes are stored in a file called Macro-CostAccrualList.xlsm,
    and this file is stored in the same folder as 11038-CAL-201906.xls and 11041-CAL-201906.xls.

    Of course there are may other ????-CAL-201906.xls files in this folder, and I just list out 2 only, and ???? are actual numeric code representing each construction project.

    The Macro file is intended to look for all these ????-CAL-1906.xls files, open them one by one, and make some adjustments, then save it, and go for another file until all these files have been adjusted.
    And BTW, it is just a normal simple module under VBA Project Explorer.

    Hope you understand.

    Thx
    Last edited by chasoe; 06-30-2019 at 08:48 AM.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Do While Loop never stops

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Do While Loop never stops

    Thanks for your prompt reply.

    1. Your codes somehow was stuck in :
    Please Login or Register  to view this content.
    2. In any case, I find that your codes included :
    Please Login or Register  to view this content.
    so I just added this codes into my original macro, and the whole thing works again and the loop can stop after finishing opening each CAL files.

    but I don't know why this EnableEvents is so important without which the loop will never end, but repeat again and again after after going through all the CAL files

    Thanks anyway as at least I can sort out where the problem is.
    Last edited by alansidman; 06-30-2019 at 12:15 PM.

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,610

    Re: Do While Loop never stops

    @chasoe
    Please wrap code with tags, even if there is only one line
    Thanks

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Another way without an object variable …


    Quote Originally Posted by chasoe View Post
    it is just a normal simple module under VBA Project Explorer.
    PHP Code: 
    Sub CAL_ALLOpen()
          
    Dim P$, F$, L&
         
    With Application
             
    .AskToUpdateLinks False
             
    .EnableEvents False
             
    .ScreenUpdating False
              P 
    ThisWorkbook.Path "\"
              F = Dir(P & "
    *CAL*.xls")
        While F > ""
              L = L + 1
            With Workbooks.Open(P & F)
                .Sheets("
    CAL-GTT").[F9].Value2 = 500
                .Close True
            End With
              F = Dir
        Wend
             .AskToUpdateLinks = True
             .EnableEvents = True
             .ScreenUpdating = True
         End With
              MsgBox L & " 
    files modified", vbInformation, "Updating CAL"
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  8. #8
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Another way without an object variable …

    Looks too advanced for me to understand, as I'm only a beginner in VBA and all the codes comes from the google search and adapted to fit my need.

    And it's bad news as the codes fail again even after adding "Enable Event" stuff.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    As it's the casual case without any attachment, so attach the main workbook (where code is)
    saved as binary .xlsb or macro .xlsm and at least a couple of source .xls files …

  10. #10
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,610

    Re: Do While Loop never stops

    @chasoe
    Please read post #6 and add tags as requested ( final warning)

  11. #11
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Do While Loop never stops

    Yes, I got the message already.

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,755

    Re: Do While Loop never stops

    Removed
    Pending Op complying with moderator instruction

  13. #13
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Do While Loop never stops

    Macro file as attached, as I need to strip off any Asian characters within the codes.
    And I think this final version can now work after several trial run.

+ 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] Creating loop that stops after certain string
    By letsExcelebrate in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2017, 05:16 PM
  2. [SOLVED] Do While ....Loop Never Stops
    By jadown in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 09:29 AM
  3. VBA - Loop stops too soon
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2013, 06:42 AM
  4. loop that stops when certain value is obtained
    By ukhan12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2013, 10:41 PM
  5. [SOLVED] A Loop does not loop throught. It stops after two cells.
    By AB33 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2012, 01:14 PM
  6. Code Stops in a loop?
    By playtowinpb@msn.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2011, 01:57 PM
  7. [SOLVED] Formula in loop stops working
    By Jim73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2005, 12:06 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