+ Reply to Thread
Results 1 to 13 of 13

How to improve performance of my code?, now is too slow!!

  1. #1
    Registered User
    Join Date
    03-02-2015
    Location
    Germany
    MS-Off Ver
    WIN 7
    Posts
    19

    How to improve performance of my code?, now is too slow!!

    Dear all,

    I hope you are well,

    I need your support, my vba knowledge does not let me find a better solution,

    I´m running a code, which is very very very not efficient ,

    Basically I have a table in sheet1 with a price list (all my products), and in the sheet2 I have the products which are listed in a specific customer, I want that my code runs throug each product on my price list and checks if that product is listed in the customer, if yes writes 1 the column "listed", if not write 0, this way the sales people have a fast view of the products they might talk with the customer to list.

    below you have my code

    Please Login or Register  to view this content.
    and here is my testing file

    search.xlsm

    Hope you can help me,

    Thank you in advance

    regards,

    Laurel

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to improve performance of my code?, now is too slow!!

    Try this:

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to improve performance of my code?, now is too slow!!

    Hi laurelb,

    Welcome to the Forum!

    Here's another to try:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: How to improve performance of my code?, now is too slow!!

    Instead of using 2 nested loops to compare every SAP# on sheet 1 with each SAP# on sheet 2, I would suggest using one loop that examines each SAP# on sheet 1 and then use MATCH to see if it exists on Sheet 2. If so, set the result for 'Listed' on sheet 1 to 1, otherwise to 0.
    This should save MANY unneeded comparisons and speed up the macro considerably.

    Something like this.
    Please Login or Register  to view this content.

    - Stu
    If this has been helpful, please click on the star at the left.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: How to improve performance of my code?, now is too slow!!

    See next Code
    Please Login or Register  to view this content.
    Some questions:
    why to start on 19 in sheet2?
    ColNum is a number of rows?
    Is it really slow ? not on my PC
    Now if it is still sloow , it can be faster, do we need
    Last edited by PCI; 08-05-2015 at 05:13 PM.
    - Battle without fear gives no glory - Just try

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to improve performance of my code?, now is too slow!!

    Why are you using VBA when the much simpler =MATCH() function directly in Sheet 1 column L would produce your answer.

    Never use VBA when standard Excel functionality is available. VBA is always more time consuming particularly when loops are involved.

    Use in L8

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to improve performance of my code?, now is too slow!!

    Never use VBA when standard Excel functionality is available. VBA is always more time consuming particularly when loops are involved.
    I don't think so

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to improve performance of my code?, now is too slow!!

    Quote Originally Posted by xladept View Post
    I don't think so

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to improve performance of my code?, now is too slow!!

    Hi Richard,

    I've had occasion to straighten out calculation bound spreadsheets and, with any serious volume, the VBA solution is always quicker.

    I know that's contrary to popular opinion, but it's true nonetheless

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: How to improve performance of my code?, now is too slow!!

    "I know that's contrary to popular opinion, but it's true nonetheless"
    I fully agree, with my experience, macros are more efficient because doing only what must be done.
    Certainly maintenance is another issue ...

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to improve performance of my code?, now is too slow!!

    Certainly maintenance is another issue ...
    To my senses, a worksheet full of formulas is just plain messy and easy to mess up

  12. #12
    Registered User
    Join Date
    03-02-2015
    Location
    Germany
    MS-Off Ver
    WIN 7
    Posts
    19

    Re: How to improve performance of my code?, now is too slow!!

    Dear All,

    thank you for your replies,

    Sorry for my late answer, I have been on vacation.

    stnkynts, xladept, StuCram and PCI, I will try the code and let you guys know ,

    Richard Buttrey, thank you for the suggestion, but I have to agree with xladept, I don´t wont to have the worksheet full of formulas, but thank you though

    Once again, thank you very much for all your support,

    Laurel,

  13. #13
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to improve performance of my code?, now is too slow!!

    Quote Originally Posted by PCI View Post
    I fully agree, with my experience, macros are more efficient because doing only what must be done.
    ..except that I've lost count of the number of times questions are asked here about slow macros which contain loops when standard Excel functionality and functions are light years faster and should be used instead of VBA

    The operative words are 'doing only what must be done'. The problem with looping macros is that the loop conditions have to be evaluated before you can even begin to decide whether to process any data. The very act of evaluation more often than not means testing something in the application and of course every time you jump backwards and forwards between VBA and the Excel Application there is a time overhead which really slows things down when large ranges are being processed.

    I really don't understand this pre-occupation with macros. Don't get me wrong, I agree they are extremely powerful and sometimes the only way to do something, but the operative word is 'sometimes'. Mostly and IMO they certainly aren't the first port of call for processing data.

+ 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] Can VBA improve the performance of this spreadsheet
    By gassiusmax in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2014, 05:19 AM
  2. improve performance
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2013, 01:12 AM
  3. Improve Performance of Form with 80 Dlookups
    By Whizbang in forum Access Tables & Databases
    Replies: 3
    Last Post: 10-18-2011, 05:11 PM
  4. How to improve the performance of a looping UDF
    By johnnycanuck in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2011, 01:39 PM
  5. Improve slow code - programming a sub which displays a polynomal function
    By reteid2222 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2008, 08:59 AM
  6. how do I improve performance when updating external links?
    By Using formulas to enter NULL cell values in forum Excel General
    Replies: 2
    Last Post: 04-06-2006, 09:50 AM
  7. PageBreak problem. How to improve performance?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2005, 09: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