+ Reply to Thread
Results 1 to 14 of 14

Making VBA faster and non freeze

  1. #1
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Making VBA faster and non freeze

    Hello

    The attached sample worksheet VBA works fine, I am requesting help on the following

    1. Short and simpler Code
    2. Faster execution
    3. Non Freeze during VBA execution
    4. Increase range Range("A5:A9") and .Range("E5:E9") till 5000 rows but check non blank rows during execution
    5. Increase range Range("A5:H9").Sort up to 5000 but this should only sort range with data else blank row will come in top
    Attached Files Attached Files
    Last edited by grcshekar; 09-19-2023 at 03:58 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    Making it not freeze would be outside the scope of a free forum, but the primary reason that it's so slow is that you're automating Internet Explorer. If you skip that step then it becomes much faster, you can use something like the below to retrieve the price from a ticker:

    Please Login or Register  to view this content.
    To reduce your code complexity, I'd have a VLookup in your summary table that brings in the actual ticker, this removes the lookup step and you only have to update the current row.
    If you look at the above code, you'll see that it requires 2 calls, one to get the internal ID of the ticker and then another to the API service with the ID to get the price. You could halve the number of requests (and therefore significantly improve performance) by saving this internal ID in your tickers table, you'd then skip straight to this step:
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    Thinking about it, if you run through and get the IDs of the Tickers, you could do it all with a formula and Excel won't freeze, something like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350
    Can You pl show me example in my Excel sheet
    Last edited by AliGW; 09-21-2023 at 03:11 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  5. #5
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Re: Making VBA faster and non freeze

    Can You pl show me example in my Excel sheet Also I cannot write

    tickers.Add "CPSEETF"
    tickers.Add "MAFANG"
    tickers.Add "HDFCSML250"
    tickers.Add "PSUBNKBEES"
    tickers.Add "MOM100"

    because it will change
    Last edited by AliGW; 09-21-2023 at 03:11 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    I know, it was an example. Did you try any of it?

  7. #7
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350
    I am re writing as per your suggestion will update shortly
    Last edited by AliGW; 09-21-2023 at 03:10 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  8. #8
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Re: Making VBA faster and non freeze

    I have incorporated your suggestion and it is working fine and faster, request help in updating Column E in sheet dashboard with output values corresponding to column A Please
    Attached Files Attached Files
    Last edited by AliGW; 09-21-2023 at 03:10 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    Why don’t you use the formula?

  10. #10
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Re: Making VBA faster and non freeze

    can you please incorporate formula in my excel sheet as I could not make it work

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    Have you done the first bit as outlined in my post where you've got the actual IDs for the tickers?

    When you have, it's simply:
    Please Login or Register  to view this content.
    Where 44412 is the ID for CPSEETF

  12. #12
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Re: Making VBA faster and non freeze

    Quote Originally Posted by Kyle123 View Post
    Have you done the first bit as outlined in my post where you've got the actual IDs for the tickers?

    When you have, it's simply:
    Please Login or Register  to view this content.
    Where 44412 is the ID for CPSEETF
    Tried it did not work hence requested you to kindly use my excel sheet

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Making VBA faster and non freeze

    Ah yes, I hadn't spotted you're using an old version of Excel.

    In that case, you can simply use my code as a UDF, so add a column after A in your dashboard sheet, to bring in the Ticker then use the following in column B
    =VLOOKUP(A5,Ticker!B:C,2,FALSE)

    Then in column F, use the formula
    =getNSEPriceForTicker(B5)

    Of course if you really didn't want the additional column, you could combine the formulas to have the following in F:
    =getNSEPriceForTicker(VLOOKUP(A5,Ticker!B:C,2,FALSE))

    You really want to add the internal IDs to the listing table though, it will make it all much faster

  14. #14
    Forum Contributor
    Join Date
    11-10-2019
    Location
    India
    MS-Off Ver
    2013
    Posts
    350

    Re: Making VBA faster and non freeze

    Quote Originally Posted by Kyle123 View Post
    Ah yes, I hadn't spotted you're using an old version of Excel.

    In that case, you can simply use my code as a UDF, so add a column after A in your dashboard sheet, to bring in the Ticker then use the following in column B
    =VLOOKUP(A5,Ticker!B:C,2,FALSE)

    Then in column F, use the formula
    =getNSEPriceForTicker(B5)

    Of course if you really didn't want the additional column, you could combine the formulas to have the following in F:
    =getNSEPriceForTicker(VLOOKUP(A5,Ticker!B:C,2,FALSE))

    You really want to add the internal IDs to the listing table though, it will make it all much faster
    Great ! This does the trick, one last question. how do I set refresh every minute so that NSE refreshes

+ 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] help in making code run faster
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-25-2017, 04:59 AM
  2. [SOLVED] Need help making this faster
    By mcsejung in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2016, 06:58 PM
  3. Making a VBA code faster
    By Human2014 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 01:20 PM
  4. making formulas faster
    By ammartino44 in forum Excel General
    Replies: 5
    Last Post: 09-20-2014, 05:56 AM
  5. [SOLVED] Help making VBA macro run faster
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2014, 08:37 AM
  6. [SOLVED] Need Help Making Macro Run Faster
    By bigkahuna2187 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-08-2012, 07:38 AM
  7. Making a report run faster
    By fodeps in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2009, 12:56 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