I want to substract maximum value and minimum value which the values are from column 'Sampel1' to column 'Sampel5'(pls see attachment).
My prob is, the result for the subtraction for column 'Julat' (pls see the attachment)
is diiferent if I calculate manually.
For instance( row 5) :
Max value = 354
Min value = 10.6
Subtraction = 354 - 10.6 = 343.4
The answer should be 343.4, not 343
Row 6 :
Max value = 21.3
Min value = 2.5
Subtraction = 21.3 - 2.5 = 18.8
The answer should be 18.8, not 19
I cant figure out what is wrong with the code.
Please help.
Thank U in advance.
Snippet code :
VB Code:
'add column MSFlexGrid7.Cols = MSFlexGrid7.Cols + 1 MSFlexGrid7.TextMatrix(0, 6) = "Purata" MSFlexGrid7.Cols = MSFlexGrid7.Cols + 1 MSFlexGrid7.TextMatrix(0, 7) = "Julat" 'mean for column Purata Dim X For X = 1 To MSFlexGrid7.Rows - 1 MSFlexGrid7.TextMatrix(X, 6) = (Val(MSFlexGrid7.TextMatrix(X, 1)) + Val(MSFlexGrid7.TextMatrix(X, 2)) + Val(MSFlexGrid7.TextMatrix(X, 3)) + Val(MSFlexGrid7.TextMatrix(X, 4)) + Val(MSFlexGrid7.TextMatrix(X, 5))) / 5 Next 'range for column Julat Dim row As Long Dim column As Long Dim Max As Long Dim Min As Long With MSFlexGrid7 For row = 1 To .Rows - 1 Max = Val(.TextMatrix(row, 1)) Min = Val(.TextMatrix(row, 1)) 'loop only for column 1 to column 5 For column = 1 To 5 If Min > Val(.TextMatrix(row, column)) Then Min = Val(.TextMatrix(row, column)) End If If Max < Val(.TextMatrix(row, column)) Then Max = Val(.TextMatrix(row, column)) End If Dim h h = Max - Min .TextMatrix(row, 7) = h Next Next End With




Reply With Quote