• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to preserve the values and then perform the if check

BST181290

New Member
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?

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:
BST181290
Your: The idea is that say...
Could You write to one Excel-sheet:
What would Your idea look like before and after run that code?
... please, could You use that sample with eg three cases and five locations?
If Your code don't give Your expected result, then do it manually
 
BST181290
Your: The idea is that say...
Could You write to one Excel-sheet:
What would Your idea look like before and after run that code?
... please, could You use that sample with eg three cases and five locations?
If Your code don't give Your expected result, then do it manually
Hi

I have attached the document for the logic.
Please let me know if it is not clear.
I tried explaining by writing the procedure in steps.
 

Attachments

  • CamScanner 02-07-2021 11.08.37 (2)_compressed.pdf
    874.3 KB · Views: 2
Last edited:
BST181290
Please, reread my previous reply
--- I tried to ask to get an Excel-file.
Did You notice that green line?
--- before and after.
As well as
--- number of cases and locations

Okay, You did ... something manually.

After those ... Your PDF-file could be useful.
 
BST181290
Please, reread my previous reply
--- I tried to ask to get an Excel-file.
Did You notice that green line?
--- before and after.
As well as
--- number of cases and locations

Okay, You did ... something manually.

After those ... Your PDF-file could be useful.
hi is the above information useful? or further more is needed?
 
BST181290
Seems You have skipped my writings.
I even used same keywords which You asked

As written above (#4 reply)
(( Now, I pasted here only three lines ))
Please, reread my previous reply
--- I tried to ask to get an Excel-file.
After those ... Your PDF-file could be useful.
 
Back
Top