Results 1 to 19 of 19

How to improve this macro to run faster

Threaded View

  1. #1
    Registered User
    Join Date
    05-19-2013
    Location
    Sarawak
    MS-Off Ver
    Excel 2007
    Posts
    10

    How to improve this macro to run faster

    Hi all expert there,

    I'm new to this website and so with the macro thing. Recently, I learn on how to use macro in simulating reservoir for hydropower project. I have managed to prepared one but it too time consuming. Can someone out there to check if there is any improvement for my vba below? Your comment is highly appreciated.
    Sub Button1_Click()
    Dim y, x As Integer
    x = Cells(18, 2).Value + 20
    For y = 21 To x
            ' First run plant discharge starts at 0.
            Cells(y, 8).Value = 0
            Do While Cells(y, 6).Value >= Cells(7, 5).Value ' Current reservoir level above MOL
                ' Increment @ 5.
                Cells(y, 8).Value = Cells(y, 8).Value + 5
                If Cells(y, 21).Value >= 0.98 * Cells(13, 11).Value Then
                ' almost there.
                Exit Do
                End If
            Loop
            Do While Cells(y, 6).Value >= Cells(7, 5).Value
                Cells(y, 8).Value = Cells(y, 8).Value + 0.1
                If Cells(y, 21).Value >= Cells(13, 11).Value Then
                Cells(y, 21).Value = Cells(y, 21).Value
                ' Rated power is achieved.
                Exit Do
                End If
            Loop
            If Cells(y, 21).Value >= Cells(14, 11).Value Then
                Cells(y, 8).Value = Cells(y, 8).Value
            ElseIf Cells(y, 21).Value < Cells(14, 11).Value Then
                Cells(y, 8).Value = 0
            End If
          
    Next y
    End Sub
    Thanks,

    jerry from Malaysia.

    Sorry for my bad english.
    Last edited by Leith Ross; 05-19-2013 at 11:03 PM. Reason: Added Code Tags

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