jerrybetie
New Member
Hi all sifu here,
My name is Jerry Betie and I'm from Malaysia. I'm new to this website. I need help to run my macro as shown below to run faster. It is basically for energy modeling from reservoir operation with daily input. I have tried to run it, but even after few hours, it still running. As I'm new to this vba pragramming, I couldn't find any better solution to run it fast. At last. I saw this website and hopefully somebody can help me to run my model below fast.
Option Explicit
Sub Button1_Click()
Dim x&, y&, A&, B&, C&, D&, vD7Value&, vJ13Value&, vJ14Value&
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
x = Cells(18, 2).Value + 20
vD7Value = Cells(7, 5).Value
vJ13Value = Cells(13, 11).Value
vJ14Value = Cells(14, 11).Value
For y = 21 To x
A = 0 ' First run plant discharge starts at 0.
B = Cells(y, 6).Value
C = Cells(y, 21).Value
D = 0.98 * vJ13Value
Do While B >= vD7Value ' Current reservoir level above MOL
A = A + 5 ' Increment @ 5.
If C >= D Then Exit Do ' almost there.
Loop
Do While B >= vD7Value
A = A + 0.1
If C >= vJ13Value Then Exit Do ' Rated power is achieved.
Loop
If C < vJ14Value Then Cells(y, 8).Value = 0 Else Cells(y, 8).Value = A
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
I can't attached the original file as it is too large to attach.
However, I can attach the original file but with different vba script. The above script is using daily flow series while the attache is using monthly flow series. The attached macro excel is taking about 15 minutes to complete in my laptop. If I using daily inflow series, it will take forever to run. This is where I need your expert help.
I really appreciate for any comments and suggestion to improve my program as above.
Thanks in advance.
jerry.
My name is Jerry Betie and I'm from Malaysia. I'm new to this website. I need help to run my macro as shown below to run faster. It is basically for energy modeling from reservoir operation with daily input. I have tried to run it, but even after few hours, it still running. As I'm new to this vba pragramming, I couldn't find any better solution to run it fast. At last. I saw this website and hopefully somebody can help me to run my model below fast.
Option Explicit
Sub Button1_Click()
Dim x&, y&, A&, B&, C&, D&, vD7Value&, vJ13Value&, vJ14Value&
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
x = Cells(18, 2).Value + 20
vD7Value = Cells(7, 5).Value
vJ13Value = Cells(13, 11).Value
vJ14Value = Cells(14, 11).Value
For y = 21 To x
A = 0 ' First run plant discharge starts at 0.
B = Cells(y, 6).Value
C = Cells(y, 21).Value
D = 0.98 * vJ13Value
Do While B >= vD7Value ' Current reservoir level above MOL
A = A + 5 ' Increment @ 5.
If C >= D Then Exit Do ' almost there.
Loop
Do While B >= vD7Value
A = A + 0.1
If C >= vJ13Value Then Exit Do ' Rated power is achieved.
Loop
If C < vJ14Value Then Cells(y, 8).Value = 0 Else Cells(y, 8).Value = A
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
I can't attached the original file as it is too large to attach.
However, I can attach the original file but with different vba script. The above script is using daily flow series while the attache is using monthly flow series. The attached macro excel is taking about 15 minutes to complete in my laptop. If I using daily inflow series, it will take forever to run. This is where I need your expert help.
I really appreciate for any comments and suggestion to improve my program as above.
Thanks in advance.
jerry.
Attachments
Last edited: