+ Reply to Thread
Results 1 to 8 of 8

Run the code faster.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Run the code faster.

    Hello friends, hope all is well!
    can you please help me make the below code run faster?

    Thank you very much in advance!

    Sub DoWhileDemo()
    
    Sheets("bmi").Range("B34").ClearContents
    
    Range("A1").Select
    
    Do Until Sheets("bmi").Range("C34").Value = True
    Sheets("BMI").Range("B34").Value = Sheets("BMI").Range("B34").Value + 1 'Sheets("BMI").Range("F34").Value
      DoEvents 'Wait for things to update
      Application.Wait (Now() + CDate("00:00:01")) / 5000
      Loop
      
    Application.ScreenUpdating = False
        Range("E34").Select
        Selection.Copy
        Range("B34").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run the code faster.

    Hi countryfan_nt

    What are you trying to achieve here?

    When do you expect this loop to terminate?:
    Do Until Sheets("bmi").Range("C34").Value = True
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Re: Run the code faster.

    B34 = the code above runs in cell B34, hence, values start from 0 and stops when C34 becomes TRUE.
    C34 formula: =IF(E34<=B34,TRUE,B34).
    E34 has the target value, to finally show the desired result.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run the code faster.

    Remove this line:
    Application.Wait (Now() + CDate("00:00:01")) / 5000
    and move this line:
    Application.ScreenUpdating = False
    above this line:
    Do Until Sheets("bmi").Range("C34").Value = True
    Last edited by kev_; 10-29-2017 at 02:24 AM.

  5. #5
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Re: Run the code faster.

    done, but still not fast enough. you see this is feeds a chart, and I wish to see the chart results run faster.
    Attached Files Attached Files
    Last edited by countryfan_nt; 10-29-2017 at 02:32 AM.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run the code faster.

    To speed up processing
    - use a variable to calculate
    - write the result to the cell when condition satisfied

    Try this:
    Sub DoWhileDemo()
        Dim B34 As Double
        Application.ScreenUpdating = False
    
        With Sheets("BMI")
           .Range("B34").ClearContents
           .Range("A1").Select
            B34 = .Range("B34").Value
          
            Do Until .Range("E34").Value <= B34
                B34 = B34 + 0.1
            Loop
           .Range("B34").Value = B34
        
          
           .Range("B34").Value = .Range("E34").Value
           .Range("E34").Copy
           .Range("B34").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        End With
        Application.ScreenUpdating = True
    End Sub

    EDIT - please note that I amended the code in a couple of places after posting
    Last edited by kev_; 10-29-2017 at 03:49 AM. Reason: Tidied up code

  7. #7
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Re: Run the code faster.

    Thank you very much!

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run the code faster.

    You are welcome. Thanks for reps and marking thread SOLVED

+ 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] Trying to get this code to run FASTER
    By g1terra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2017, 02:23 PM
  2. vba code to run faster
    By ikhan99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2016, 02:19 AM
  3. [SOLVED] Get a code to run faster
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2015, 02:07 AM
  4. Making a VBA code faster
    By Human2014 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 01:20 PM
  5. Can code run faster
    By leem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2010, 02:52 PM
  6. I need faster code
    By mpeplow in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2007, 05:30 PM
  7. [SOLVED] Faster way to code this
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-06-2006, 12:08 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