I have to do a little programming in Excel. I'm struggeling with this code. I have completed all of it, but I cant seem to make it work.
I want it to calculate d in the following equation.
((W - 2 * x * (H - d)) * (L - 2 * x * (H - d)) + (W - 2 * H * x) * (L - 2 * H * x)) * 0.5 * d
I have done most of the code, the problem is it doesn't want to calculate a lot of values at once.
This is the code:
Code: Select all
Option Explicit
Dim W As Double
Dim x As Double
Dim H As Double
Dim L As Double
Dim V As Double
Dim d As Double
Dim A As Double
Private Sub CommandButton1_Click()
Dim c As Double
Dim x As Integer
c = 63
W = Cells(17, 9).Value
x = Cells(18, 9).Value
H = Cells(18, 4).Value
L = Cells(17, 4).Value
Range("E63").Select
Do Until IsEmpty(ActiveCell)
d = 0
V = ActiveCell.Value
A = Round(((W - 2 * x * (H - d)) * (L - 2 * x * (H - d)) + (W - 2 * H * x) * (L - 2 * H * x)) * 0.5 * d, 1)
V = Round(V, 1)
If A <> V Then
d = d + 0.00001
'Cells(c, 6).Value = 0
'Cells(c, 16).Value = 0
Else
Cells(c, 6).Value = d
Cells(c, 16).Value = A
c = c + 1
If IsEmpty(ActiveSheet.Cells(c, 5)) Then
Exit Sub
Else
d = 0
End If 'If IsEmpty(ActiveSheet.Cells(c,5) Then
End If 'If A <> V Then
'If IsEmpty(ActiveCell) Then
' Exit Do
' Else
' ActiveCell.Offset(1, 0).Select
' End If 'If IsEmpty
Loop 'Do Until...
End Sub
W : Width
L : Length
x : is slope (i.e 1 : x )
H : Total depth of dam
d : depth of water at any given time
As you can derive, it has to calculate dimension etc. of a dam.
ANY HELP will be appreciated.
Thanks guys!