+ Reply to Thread
Results 1 to 14 of 14

My macro runs endlessly & have to force excel to close to stop it

  1. #1
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    My macro runs endlessly & have to force excel to close to stop it

    Hi all,

    This is my first post in this forum & i am new to macro, therefore please excuse my lack of technical knowledge in this area.

    I have a macro that i use to transpose contact information that is in vertical column to horizontal rows. Once the contacts are transposed to horizontal rows the macro then goes on to remove the empty rows that are between the between the contacts. However when i run the macro it runs endlessly instead of stopping when there is no more data, which in in this case is at row number 1884. Why will the macro not stop when there is no more data & how does the macro need to be changed to make it stop at the last contact?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    You are falling in to infinite loop.

    Do Until IsEmpty(ActiveCell)

    Until the active cell becomes empty, the code will go on looping. It will only stop when you run out of memory or use brute force.
    If you are new to programming, avoid while and do loops, instead use for loop which has a start and end points.

  3. #3
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Thank you for your response.
    Like i said i have only been at this for a day.
    Are recommending that the following code be removed?
    Please Login or Register  to view this content.
    If so could you let me know what code should be inserted & where it should go in my macro?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    No,

    Do Until IsEmpty(ActiveCell)

    saying that going on looping until the active cell which is where the cursor happens to be is empty. In other words, the code will keep looping until this condition is met. The reason for endless loop is you keep copying and active cell will never be empty. So, the code searching for empty cell and keep searching until it finds empty.
    This code is from recoded macro. If you could attach a sample, I will give you different ways of looping.

  5. #5
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Thanks again, trying hard to get my head around this.

    Here is some sample contact information from the vertical column. Note that a contact information takes up four lines:
    Gamini Abeysinghe Abr
    Re/Max Diamond Realty Inc.
    1570 Kipling Avenue
    Toronto, Ontario M9R2Y1
    Wasantha Abeysiri
    Homelife Landmark Realty Inc.
    7240 Woodbine Ave Unit 103
    Markham, Ontario L3R1A4
    Azhar Abrar
    Kingsway Real Estate Brokerage
    151 City Centre Drive #300
    Mississauga, Ontario L5B1M7
    Leonor Agosto Henry
    Keller Williams Advantage Realty
    1238 Queen St East Unit B
    Toronto, Ontario M4L1C3

    Then when i transpose it to one row of information for each contact, i want to look like this:
    Gamini Abeysinghe Re/Max Diamond Realty Inc. 1570 Kipling Avenue Toronto, Ontario M9R2Y1
    Wasantha Abeysiri Homelife Landmark Realty Inc. 7240 Woodbine Ave Unit 103 Markham, Ontario L3R1A4
    Azhar Abrar Kingsway Real Estate Brokerage 151 City Centre Drive #300 Mississauga, Ontario L5B1M7
    Leonor Agosto Henry Keller Williams Advantage Realty 1238 Queen St East Unit B Toronto, Ontario M4L1C3

    And the macro needs to remove all the three rows that are empty, in between each contact.

    Here is the code again:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: My macro runs endlessly & have to force excel to close to stop it

    This might work... Happy to explain if you cannot follow th elogic.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    The main reason for infinite loop was of the active cell. If the curosor was in A1, you would not got the problem.


    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Thank you.
    Could you explain?
    I copied & pasted this code into the macro & tried it but nothing happened.
    Just to clarify, my contact information is currently all in the B Column with four vertical cells containing the contact
    infor for each contact. I want to transpose it to this contact information to so that it is in one horizontal row across
    four columns (column C to F). When the data is transposed from the vertical column to a row there are three empty rows between
    each contact, which i want the macro to remove.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Thank you,
    Does any part of my current macro need to be removed & this inserted in its place?
    or should i just copy & paste this code to the end of my current macro?

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    No, this is a complete new code. Just copy the code in to a module.
    The code does not create or delete empty rows.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: My macro runs endlessly & have to force excel to close to stop it

    Or, you want like


    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Unbelievable, that fixed the problem!
    I take my hat off to you sir.
    Could you explain the logic to me?
    I have been working on this for 12 hours straight & was at my wits end.
    Do not know how to how grateful i am for your helP.
    Thank you, so much!

  14. #14
    Registered User
    Join Date
    04-11-2017
    Location
    Toronto, Canada
    MS-Off Ver
    Office 365
    Posts
    7

    Re: My macro runs endlessly & have to force excel to close to stop it

    Unbelievable, that fixed the problem!
    I take my hat off to you sir.
    Could you explain the logic to me?
    I have been working on this for 12 hours straight & was at my wits end.
    Do not know how to how grateful i am for your helP.
    Thank you, so much!

+ 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. Disable close workbook but still force users to close thru command button
    By rathig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2013, 07:29 AM
  2. [SOLVED] Macro runs perfectly, but dialog box doesn't close automatically
    By Bunnyla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2012, 01:12 PM
  3. How do I force Excel to stop helping me
    By david488 in forum Excel General
    Replies: 2
    Last Post: 11-26-2009, 04:27 AM
  4. Program appears to loop endlessly, have to force quit
    By Danexcel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-18-2009, 12:09 PM
  5. Macro runs on wrong workbook on close
    By Cumberland in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-30-2009, 07:47 AM
  6. How to stop other macros while current macro runs
    By Paul987 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2006, 12:20 PM
  7. Replies: 4
    Last Post: 02-02-2006, 03:45 PM
  8. [SOLVED] Macro to force Excel to close after a given timeframe of inactivit
    By bobm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2005, 10:05 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