+ Reply to Thread
Results 1 to 19 of 19

Why is my VBA script exiting early?

  1. #1
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Why is my VBA script exiting early?

    Hey all, I am interning and I have a VBA script that is linked to "Thisworkbook" which is as follows
    Please Login or Register  to view this content.
    when I step through the code to analyze it the code works fine about 90% of the time however the other 10% of the time the code gets to the line of code that trims the B column and it just leaves this script and goes into the code I have in my inserted module which is
    Please Login or Register  to view this content.
    This function exists in none of the columns that are being evaluated by the program so I am unsure why its being called and why the program is leaving the original macro that I am stepping through. Am I missing something in my code that should make this happen? I unfortunately cant attach the file due to confidentiality reasons.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,050

    Re: Why is my VBA script exiting early?

    Here, as a location, isn't very helpful. The syntax of a formula will vary depending on your Regional Settings. We don't need your address and post code/zip code, but the country, or even the continent would be useful.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    I think I have created and attached a file, not 100% sure on the attachment. For some reason I cant even step through the macro that works on workbook open on this test file. I changed nothing from the code
    Attached Files Attached Files

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,038

    Re: Why is my VBA script exiting early?

    Your code runs fine for me, however, your file seems to hang alot...Could be that it has become corrupt...
    Let's ignore your code for now...
    Please explain what it is you are actually wanting to achieve...
    Is it...Matching Ex 1, 2 & 3 with Template In Col B and if not exact match then red else green and then adding these colour up per column...

    I am very certain that if you explain your thought process, someone will be able to find a answer...
    Last edited by Sintek; 08-08-2024 at 03:13 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Why is my VBA script exiting early?

    Try setting calculation to manual when executing the code then set it back to automatic afterwards. I would assume that your Open event would resume in the end anyway.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,050

    Re: Why is my VBA script exiting early?

    Just wondering why you check if the cell is empty. As far as I know, if you trim an empty cell, the formula will return a null value ( "" ).

  7. #7
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    I check if the cells in the columns after B are empty mostly because in the real file I have some of the locations that have a blank value some specific rows. when I first ran the file it would sometimes get to the line nochar/string and the program would absolutely freeze. I was assuming that the program was trying to do something similar to dividing by zero so I put those lines in and it seemed to fix that issue. I only trim B because the templates are user created and sometimes people add spaces that we dont want. I didn't trim the other columns because I want to preserve and signal any errors that may be in the rows so those individual locations can fix them in their personal file locations As to the question someone else asked of what I want to achieve, as I had stated before this code runs fine about 90% of the time and then about 10% of the time when I run it, excel freezes and crashes. When I try to figure out why by stepping through the program it randomly exits the macro at the trim line and enters the lines of code for the getcolor function. I am assuming this is what is causing the crash, my end goal is to understand why excel is randomly exiting the macro early/or figure out why about 10% of the time running the code causes excel to absolutely crash. For reference in the 90% of the time it runs fine, the program takes about 20 seconds to run. In the 10% that it fails there have been instances where ive left if for 10 minutes before touching it.

  8. #8
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    I added Application.Calculation = xlCalculationManual at the beginning of the code and Application.Calculation = xlCalculationAutomatic at the end and ran the program again. Once I clicked the run button excel instantly went to not responding. My issue persists.

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,038

    Re: Why is my VBA script exiting early?

    See post 4

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Why is my VBA script exiting early?

    No issues with your sample workbook. How many cells are in the ranges being used by your UDF (which is inherently flawed by the way)?

  11. #11
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    520 cells and it runs twice per column, 9 columns per sheet, for 5 sheets. What is the flaw?

  12. #12
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    Sintek, post 4 has been addressed. If you needed more specific information than is present in post 7 you'll have to clarify.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Why is my VBA script exiting early?

    Changing a cell colour does not cause a recalculation, so there is no guarantee that your counts will be accurate.

  14. #14
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    Should it recalculate upon opening the workbook? If not I guess I could just add two counters to my similarity checker and have it print the results on the bottom.
    Last edited by MDLovitt; 08-08-2024 at 11:26 AM.

  15. #15
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,038

    Re: Why is my VBA script exiting early?

    Post 4 has not been addressed...
    Please explain what it is you are actually wanting to achieve...
    Is it...Matching Ex 1, 2 & 3 with Template In Col B and if not exact match then red else green and then adding these colour up per column...

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Why is my VBA script exiting early?

    Looking at your code, I think you'd be better off having columns with functions for the similarity scores, then use conditional formatting to colour the cells. Your totals functions can then use the values in the additional columns to calculate, and they will always be accurate.

  17. #17
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    Quote Originally Posted by Sintek View Post
    Please explain what it is you are actually wanting to achieve...
    my end goal is to understand why excel is randomly exiting the macro early/or figure out why about 10% of the time running the code causes excel to absolutely crash.
    It has been addressed. I indicated that I am looking more for a possible answer to why the macro is randomly exiting, you are trying to help me with a different task, coding the problem. I am not looking for anyone here to write code for me, thats lazy. I am looking for an answer to a question of why is excel behaving this way with the given code.

  18. #18
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,038

    Re: Why is my VBA script exiting early?

    Alrighty then...Get rid of your function and do your counts during your loops...

  19. #19
    Registered User
    Join Date
    07-18-2024
    Location
    United States
    MS-Off Ver
    MS 365
    Posts
    39

    Re: Why is my VBA script exiting early?

    Quote Originally Posted by romperstomper View Post
    Looking at your code, I think you'd be better off having columns with functions for the similarity scores, then use conditional formatting to colour the cells. Your totals functions can then use the values in the additional columns to calculate, and they will always be accurate.
    doing this seems to have fixed it, not sure why the function would interact with the macro, but either way deleting the function seemed to fix it. Thank you for your help.

+ 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] Run macro once exiting chart (or just before exiting chart)
    By Dbroek in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2022, 01:46 PM
  2. [SOLVED] Function/sub exiting early except when called from Developer tab
    By pp57 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-23-2020, 07:26 PM
  3. Need A Fast Script To Copy 80000 Cells But My Current Script Is Too Slow
    By Genus Max in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2019, 09:54 AM
  4. Hello - Need Help with Early Dates
    By Lewis61944 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 01-31-2017, 10:22 AM
  5. Early vs Latebinding is one better than the other?
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2015, 05:38 AM
  6. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  7. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM

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