+ Reply to Thread
Results 1 to 7 of 7

VBA Code on Rows consumed lot of Time

  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Lightbulb VBA Code on Rows consumed lot of Time

    Hi All,

    I am looking to reduce the run time in the below VBA code. The data size its applied is around 5000 rows.

    Is there any better way to design these to reduce the processing time.
    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Code on Rows consumed lot of Time

    I notice two things:

    You are inserting R1C1 formulas into one row at a time. This could be done in one operation instead of a loop.

    You are doing a copy & paste with several lines that could be done with an assignment in one line.

    Try this. I cannot test this without your file but I would be happy to do so if you attach it.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: VBA Code on Rows consumed lot of Time

    Also without seeing the full code, if your not already doing so it is recommended to disable calculation and then turn it back on at the end. Do a search for tips on speeding up vba code

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: VBA Code on Rows consumed lot of Time

    Thank you for all the suggestions.

    @ptmuldoon, I have used your tip on switching off and on calculations.

    @6StringJazzer: The Copy and paste I have tried to do all at once, and its fine.

    But the problem is the time taken for Calculations once the functions are input in the range. It takes over 15 minutes to complete calculations for around 3500 rows of data.

    I am wondering if there is a better way to identify the Minimum Value (with multiple criteria columns) using VBA codes instead of functions.

  5. #5
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: VBA Code on Rows consumed lot of Time

    May be we can avoid comparing whole columns.

    I have lrow2 (Last_Row) variable identified from the "Diff_Names" sheet. So how can I use that as part of the Range Reference inside my functions,
    e. g. instead of: Diff_Names!C2
    something like: Diff_Names(R2C2:R&lrow2&C2) ??? am I going the right way ?

  6. #6
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: VBA Code on Rows consumed lot of Time

    Can you post up a sample file for us to look at?

  7. #7
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: VBA Code on Rows consumed lot of Time

    Thanks for all the help.

    The issue was due to comparison of Whole Columns used inside Array Functions.

    I have manged to limit them with the use of Last Row variable.

    HTML Code: 
    Now its all good.

+ 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. Time to Execute Code when Deleting Rows
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-17-2015, 07:34 PM
  2. [SOLVED] Code to group rows with the same time value?
    By bvercher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2015, 11:07 AM
  3. Replies: 8
    Last Post: 07-12-2012, 06:23 AM
  4. inventory stock+dispatch+monthly consumed
    By hyderabadi in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 05-26-2012, 11:11 AM
  5. inventory stock and consumed
    By hyderabadi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-27-2011, 05:38 PM
  6. how do i calculate energy consumed in excel?
    By toffee_pie in forum Excel General
    Replies: 4
    Last Post: 02-26-2006, 04:43 PM
  7. [SOLVED] compute insulin doseage with carb consumed & BS readings
    By Jim and Val Hisle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-14-2005, 01:05 AM

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