jerrybetie
New Member
- Joined
- May 20, 2013
- Messages
- 1
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.
<code></code>
<code></code>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
' Current reservoir level above MOL
Do While Cells(y, 6).Value >= Cells(7, 5).Value
' Increment @ 10.
Cells(y, 8).Value = Cells(y, 8).Value + 10
If Cells(y, 21).Value >= 0.99 * 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
Exit Do
' Rated power is achieved.
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
I tried to attach the file here but failed to do so.
Thanks,
jerry from Malaysia.
Sorry for my bad english.
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.
<code></code>
<code></code>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
' Current reservoir level above MOL
Do While Cells(y, 6).Value >= Cells(7, 5).Value
' Increment @ 10.
Cells(y, 8).Value = Cells(y, 8).Value + 10
If Cells(y, 21).Value >= 0.99 * 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
Exit Do
' Rated power is achieved.
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
I tried to attach the file here but failed to do so.
Thanks,
jerry from Malaysia.
Sorry for my bad english.
Last edited: