hi everyone,
I am currently writing a code for an iteration.
The idea is that say I have 10 cases and for each of the case i have to calculate a variable named stress over 100 locations. now i first perform for the first case and then move to the second case and so on. the check i want to make is that if in anyone of the case, if the variable named stress is less than zero then the corresponding variable called as area should be zero. i want the vba to perform this check for all the 100 locations and for all the cases(10 here).
I tried to write the code as below and have used redim and preserve as well, but of no use. can any one help me in this regard?
I am currently writing a code for an iteration.
The idea is that say I have 10 cases and for each of the case i have to calculate a variable named stress over 100 locations. now i first perform for the first case and then move to the second case and so on. the check i want to make is that if in anyone of the case, if the variable named stress is less than zero then the corresponding variable called as area should be zero. i want the vba to perform this check for all the 100 locations and for all the cases(10 here).
I tried to write the code as below and have used redim and preserve as well, but of no use. can any one help me in this regard?
Code:
Private Sub CommandButton1_Click()
Dim area(1 To 100) As Double, i As Integer, cgx(1 To 100) As Double, cgy(1 To 100) As Double, Bx As Double, By As Double, Ixx(1 To 100) As Double, Iyy(1 To 100) As Double, n As Integer, j As Integer
Bx = Cells(5, 16).Value
By = Cells(6, 16).Value
For i = 1 To 100
area(i) = (Cells(6, 16).Value * Cells(5, 16).Value) / 100
Next i
For i = 1 To 10
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 1) * Bx)
Next i
For i = 11 To 20
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 11) * Bx)
Next i
For i = 21 To 30
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 21) * Bx)
Next i
For i = 31 To 40
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 31) * Bx)
Next i
For i = 41 To 50
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 41) * Bx)
Next i
For i = 51 To 60
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 51) * Bx)
Next i
For i = 61 To 70
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 61) * Bx)
Next i
For i = 71 To 80
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 71) * Bx)
Next i
For i = 81 To 90
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 81) * Bx)
Next i
For i = 91 To 100
cgx(i) = (1 / 10) * ((Bx / 2) + (i - 91) * Bx)
Next i
For i = 1 To 10
cgy(i) = By / 20
Next i
For i = 11 To 20
cgy(i) = 3 * (By / 20)
Next i
For i = 21 To 30
cgy(i) = 5 * (By / 20)
Next i
For i = 31 To 40
cgy(i) = 7 * (By / 20)
Next i
For i = 41 To 50
cgy(i) = 9 * (By / 20)
Next i
For i = 51 To 60
cgy(i) = 11 * (By / 20)
Next i
For i = 61 To 70
cgy(i) = 13 * (By / 20)
Next i
For i = 71 To 80
cgy(i) = 15 * (By / 20)
Next i
For i = 81 To 90
cgy(i) = 17 * (By / 20)
Next i
For i = 91 To 100
cgy(i) = 19 * (By / 20)
Next i
For i = 1 To 100
Ixx(i) = (Bx / 10) * ((By / 10) ^ 3) / 12 + (Bx / 10) * (By / 10) * (((By / 2) - cgy(i)) ^ 2)
Iyy(i) = (By / 10) * ((Bx / 10) ^ 3) / 12 + (Bx / 10) * (By / 10) * (((Bx / 2) - cgx(i)) ^ 2)
Next i
n = Cells(7, 16).Value
ReDim Stress(1 To n, 1 To 100) As Double
For j = 1 To n
For i = 1 To 100
Stress(j, i) = (Cells(j + 18, 9).Value) / (100 * area(i)) + (Cells(j + 18, 10).Value * (0.5 * By - cgy(i))) / (Application.WorksheetFunction.Sum(Ixx)) + (Cells(j + 18, 11).Value * (0.5 * Bx - cgx(i))) / (Application.WorksheetFunction.Sum(Iyy))
Next i
Next j
End Sub
Last edited by a moderator: