+ Reply to Thread
Results 1 to 13 of 13

code clean up

  1. #1
    Registered User
    Join Date
    11-24-2010
    Location
    antwerpen
    MS-Off Ver
    Office 365
    Posts
    30

    Question code clean up

    Hi there,

    I made a vba code with double click function

    i wonder if there is a cleanup necessary for make it go faster?

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor bonny24tycoon's Avatar
    Join Date
    04-02-2012
    Location
    Hell
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    405

    Re: code clean up

    Hi Ya,

    Not sure what does the macro do? But I dont see any unwanted codes in there.


    Thanks,

    Bonny Tycoon



    **If I was able to help please click the small star icon at the bottom left of my post **

  3. #3
    Registered User
    Join Date
    11-24-2010
    Location
    antwerpen
    MS-Off Ver
    Office 365
    Posts
    30

    Re: code clean up

    Ok thanks

    is there no way to speed up the code? because its verry slow.

    bye the way its for a sport event. for the scoring paper.

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: code clean up

    One way:

    Change this line
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Then at the end just before you exit the sub, turn everything back on via:

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  5. #5
    Forum Contributor bonny24tycoon's Avatar
    Join Date
    04-02-2012
    Location
    Hell
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    405

    Re: code clean up

    Hi,

    I dont see a challenge as to why it would be slow.. Is the source data too big??

    Thanks,

    Bonny Tycoon



    **If I was able to help please click the small star icon at the bottom left of my post **

  6. #6
    Registered User
    Join Date
    11-24-2010
    Location
    antwerpen
    MS-Off Ver
    Office 365
    Posts
    30

    Re: code clean up

    Quote Originally Posted by AlvaroSiza View Post
    One way:

    Change this line
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Then at the end just before you exit the sub, turn everything back on via:

    Please Login or Register  to view this content.
    when i use this code its quicker but the calculation isn't working and the next cel i double click the function isn't working anymore.

  7. #7
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: code clean up

    When changing calculation to manual using code, it is best not to assume the current method is automatic. Store the value in a string variable before you change it to manual. Then use the string variable to change it back at the end.

    Also, read this:
    http://blogs.office.com/b/microsoft-...practices.aspx

    You can also use With...End With to clean things up a bit. Also, avoid Select as much as possible.

    Please Login or Register  to view this content.
    Last edited by Whizbang; 04-30-2012 at 01:18 PM.

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: code clean up

    promoboy2,

    Give this a try:
    Please Login or Register  to view this content.
    Last edited by tigeravatar; 04-30-2012 at 05:05 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  9. #9
    Registered User
    Join Date
    11-24-2010
    Location
    antwerpen
    MS-Off Ver
    Office 365
    Posts
    30

    Re: code clean up

    Thank you all

    i tried everything you suggested and found the fastest way.

  10. #10
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: code clean up

    AlvaroSiza, I hope you don't mind me sharing this, but others may benefit from the question/answer.

    Quote Originally Posted by AlvaroSiza
    Whiz,

    Thanks for the heads up on capturing the current calculation state prior to switching. As I am always learning, what is the benefit of passing the state to string and using the string to 'reset to default state' versus just xlManual / xlAutomatic?

    Assume a user's default state is manual and I utilize that default state string (e.g. 'strCalcMode') during my close-out procedures. My code would then lack the re-calculation inherent (and which I am counting on) in the xlAutomatic switch. Under this scenario, I have effectively told excel during initialization of the sub to go to manual (which is my default state and would therefore be redundant and unneccesary) and then at code wrap-up, reset to the default state once again, having never achieved a sheet recalculation.

    Am I off? Happy for the pointers and thanks again,

    -as-
    By changing the calculation state via VBA, you change the expected behavior. A user that has it set as manual will expect it to stay in manual after the code is run. And of course the opposite is true. But then, as you point out, it may be that calculation does not occur because you are changing from manual to manual. The fix for this is to force a calculation when necessary.

    Please Login or Register  to view this content.
    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    The nice thing about the Calculate method is that you can calculate the entire workbook, a specific sheet, or even a specific range.

  11. #11
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: code clean up

    There's some good information about this topic at this link as well:

    http://www.ozgrid.com/VBA/calc-stop.htm

  12. #12
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: code clean up

    Quote Originally Posted by Whizbang View Post
    AlvaroSiza, I hope you don't mind me sharing this, but others may benefit from the question/answer.
    Of course not. Thank you for a thoughtful response.

    -as-

  13. #13
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: code clean up

    Deleted. Moved to new thread.
    Last edited by AlvaroSiza; 05-03-2012 at 06:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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