Closed Thread
Results 1 to 16 of 16

Is this program as efficient as it could be?

  1. #1
    overbet
    Guest

    Is this program as efficient as it could be?

    I posted a question on this forum yesterday as I was amazed at how many people were willing to help. I was given a solution to my problem along with a few other (and better) ways to solve my problem. What I was most amazed about is that those that volunteered their time to give me assistance, actually went beyond what I ever expected by offering suggestions and fixes to other parts of the code to make my program faster. I am very new and not at all skilled enough to write the attached code but I am trying to learn. I am half way through my VBA for beginners book and did one Excel VBA tutorial lesson online. I am trying to learn by reverse engineering the 2 written functioning programs I have now. Today am posting the 2nd program and I ask anyone who has time or interest to take a look and please help me make the program run faster. Thank you for the help.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Is this program as efficient as it could be?

    Hmm Overbet,

    We met before and then you posted a specific question we could help you with.

    This time you ask us for a code review for several modules.

    Sure the code can be optimized, I even see possible errors, but these kind of questions mainly remain unanswered.

    It's better to specify what you want the code to do step by step and even post several threads step by step.

    Now you ask us to look, but what are we looking at?
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Is this program as efficient as it could be?

    Without making a big deal about how these two ranges overlap, this can be simplified:
    Please Login or Register  to view this content.
    Without some understanding of what's going, mentioned already above by RW, then I can't see how this syntax is better than this:
    Please Login or Register  to view this content.
    ...since it appears the formatting is the same in the column anyway.

    ========
    Same idea, this can be simplified to remove the unnecessary "selecting":
    Please Login or Register  to view this content.
    ===========
    This long macro appears to evaluate the active cell in row 12, if it is greater than zero, then do some actions...it can be simplified...all of this:
    Please Login or Register  to view this content.
    ...down to this I think:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Is this program as efficient as it could be?

    What I saw was this
    Please Login or Register  to view this content.
    This can be replaced with
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Is this program as efficient as it could be?

    ... and this one
    Please Login or Register  to view this content.
    with this
    Please Login or Register  to view this content.

  6. #6
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    The program submits buy and sell orders for stocks when ran. It submits buys and sells around the last price and envelopes the market. It pulls in data through a dde link. I can tell you what the program does in the excel portion. Column B is stock symbol Column C and E are the prices of the buy and sell orders it is going to submit. Column D is last price of stock F is the number of buys and sells for that symbol. G is the amount away from the last price it will submit the buy and sell orders. I and AD is the quantity of shares to send AE is the exchange or destination of the order. AF is Time in Force. EXT means Extended Hours. So the program is submitting orders in the after hours market. J and AI are the average volume of the security. AG and AH are old and could be deleted. The other stuff I do not know what it is does and I have never changed it. In the code I know module 4 is where the run button refers to and this is the important part of the program that sends the orders out. Module 41 I know the redilink part is so you can change a lot of symbols with ease. That is the extent of my knowledge. I run this program every day many times a day and it is slow and kills my machine while it is running. It is so slow we are considering hiring a programmer to write something similar in C# or C++ for us because Excel is much slower for this type of program than those other languages would be. Anyway, thanks for looking, just took a stab that it might be improved easily by someone who knew what they were doing, because of the response to my request for help yesterday. Sorry I cant help you help me any better than that. Thanks again I will try the suggestions you all have posted.

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Is this program as efficient as it could be?

    hi all,

    Ricardo,
    I suggested to Overbet that he put the code up for comment - so any fault for trying to shortcut the system (specific questions) sits with me. From looking it his previous code (perhaps the same thread you've seen?), I thought there were some things that we could help with in terms of general learning & then possible code overhaul (eg from cell looping to in memory array processing*).

    Overbet,
    JB & Ricardo have given you some good suggestions so far. Are you able to make these changes, review your code for & incorporate With statements (eg "With Activecell") anywhere where the same object is acted on repeatedly, and then repost a file with the shortened code?
    As Ricardo mentioned the intent of the code is important too, so where you can, try including comments within the shortened code that explain the intent. This may help us identify different/quicker approaches such as in memory array processing (see below links for some knowledgeable comments).

    *These may be a bit of a leap but they will expand your knowledge!
    http://www.avdf.com/apr98/art_ot003.html (perhaps some is outdated now but see concept of Tip 1)
    http://www.dailydoseofexcel.com/arch...nge-using-vba/
    http://www.dailydoseofexcel.com/arch...ays-explained/

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  8. #8
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    I will work on making those changes and test run the optimized version Monday (which is the soonest I am able to). I will repost the revised version if it runs correctly. I appreciate the links and I will try dive into those later today. Thanks

  9. #9
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    I made the recommended changes and will give it a test run tomorrow. Rob, I read the links you sent thank you. I need to do more reading before I understand arrays. I attached the program again with the recommended changes made. Is the array method to optimize that you are suggesting might benefit me able to handle a lot of constantly updating data? I have another program that I was told has an array in it but the problem with that program is that it only can handle reading data from about 50 symbols at once where as the other programs you have seen of mine can handle 600 symbols at once. The 2nd attachment I was told uses an array to pull in quotes. Is this the same array you are referring to or something different? Thanks Jason
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Is this program as efficient as it could be?

    howdy,
    I've had a play with the code (see attached) & I'll respond to your questions in the last post tomorrow - fingers crossed for the testing!

    hth
    Rob
    Attached Files Attached Files

  11. #11
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    Rob, OMG! what an awesome surprise! Thank you so much for all of your effort and your expertise! I am excited about giving them a try tomorrow. My fingers are crossed too. I ran the other one today and had a couple errors I am trying to figure out. Will let you know when I get it resolved. Im looking forward to work tomorrow now!! hehe Thanks Jason

  12. #12
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    I asked someone in my office who is more familiar with vba than i am and he is also familiar with the rediplus api that we are interacting with and I was told that he does not think an array would help. He asked if you were suggesting that I pull in 10 stock prices at once and submit orders for them at once? He then said we can not pull in price feed in array so he didnt think it would work. He also said he didnt think that was the bottle neck. Does that make sense? Thanks Jason
    Last edited by overbet; 01-05-2010 at 02:14 PM.

  13. #13
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Is this program as efficient as it could be?

    Hi Jason,

    I re-read the array links as well, there are some things that still trip me up each time I use them!
    Using VBA arrays (Variant arrays, in this case to make it easier to copy from the sheet to VBE & vv) should be quicker than processing cell by cell which means the macro will take less time to run when asked (while constantly updating data).
    I may get my terminology wrong here, but I'll have a go...

    Quote Originally Posted by overbet View Post
    I have another program that I was told has an array in it but the problem with that program is that it only can handle reading data from about 50 symbols at once where as the other programs you have seen of mine can handle 600 symbols at once.
    What does "at once" mean?
    I imagine there are other issues in the file if it is only able to manage 50 symbols. An array processed in memory should be cope, but it does depend what it's doing. In the files in this thread, I have used arrays to "hold" the information from the spreadsheet in memory, so the macro doesn't have to find them from the sheet one by one.
    How big is the file?
    Is it slow to recalculate?

    Quote Originally Posted by overbet View Post
    The 2nd attachment I was told uses an array to pull in quotes. Is this the same array you are referring to or something different? Thanks Jason
    Ummm... I'm not sure, I think the array in the second attachment must have been inside the "redilink" application...?

    I ran out of steam before posting the 2 files which is why there are some asterisked sections in the "redilink" section of the OPG Test file.

    Let us know if you have any questions...

    A good way to help figure out the problems is to bring up the Locals window in the VBE & step through the code a line at a time using [F8] (maybe put "Stop" as the first line in each macro). You can even use a Watch window to tell you when something changes.

    hth
    Rob

  14. #14
    overbet
    Guest

    Re: Is this program as efficient as it could be?

    Rob, When I say at once I mean I can only get data on 50 symbols at a time if I try to put more in the sheet crashes or system slows down too much. I do step through the program before trying to run it. Will keep working and post progress. Thanks again Jason

  15. #15
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Is this program as efficient as it could be?

    howdy,

    hmmm...
    The only other thing I can think of that may play a part in the slowdown & could possibly be overcome is to turn off the calculation etc (lots of others too) during the macro, which is fine as long as the macro doesn't rely on calculated values.
    Check out RoyUk's example in post five of http://www.excelforum.com/1867848-post5.html

    btw, here's another link for some light reading (accelerated learning if you have things to apply it to). In fact, If you're in the mood, I suggest devouring the whole of Charles' site: http://www.decisionmodels.com/calcsecrets.htm

    Rob

  16. #16
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Is this program as efficient as it could be?

    hi Jason,

    Quote Originally Posted by overbet
    ...I have been stepping through my code and getting an error right away under module 4 of NY-A-test. It is the 13th line of code ignoring the comments. It is saying compile error variable not defined and it highlights the word "done =" False. Someone told me I need to define the variable but I dont know how to fix this yet so kinda stuck at the moment....
    The use of "option explicit" is what is identifying/forcing this compilation error & it's good because it stops any potential errors being hidden/ignored. If "option explicit" is not used, the computer creates a variable when it reaches that line of code. Although harmless in this situation, it can cause problems if a variable is created due to a simple spelling mistake eg

    Please Login or Register  to view this content.
    This should sort you out for this one
    Please Login or Register  to view this content.
    hth
    Rob

Closed 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