Frustrated at VBA

Mar 13, 2010 03:31



What's wrong with this?
The program works, BUT Sum(Vals) always ends up as 0.

I think there's something wrong with the way I'm compiling/making the Vals() array,
but I can't seem to fix it.

If someone can help me, that would really be awesome. :) Thanks! >:D<

---------------------------------------------------------------------------------------
Function Sum(ParamArray Arr() As Variant) As Single
    Dim All As Single
    Dim i As Integer
    All = 0
    For i = 1 To UBound(Arr)
        All = All + Arr(i)
    Next i
End Function
---------------------------------------------------------------------------------------
Sub Trial()
Dim Vals As Variant
Vals = Array()
Dim num, odd, b As Integer
num = 0
odd = 0
b = 0
Do Until ActiveCell.Offset(1, 0) = ""
    Dim a As Integer
    a = 0
    Do Until ActiveCell = ""
        Dim Result As Integer
        Result = ActiveCell Mod 2
            If Result = 1 Then
                odd = odd + 1
            ElseIf Result = 0 Then
                odd = odd
            End If

ReDim Vals(num)
        Vals(num) = ActiveCell.Value
        num = num + 1

ActiveCell.Offset(0, 1).Select
        a = a - 1
    Loop
    ActiveCell.Offset(1, a).Select
    b = b - 1
Loop
ReDim Vals(0 To num)

ActiveCell.Offset(b + 2, 2 - a).Range("A1").Value = Sum(Vals)
ActiveCell.Offset(b + 5, 2 - a).Range("A1").Value = odd
End Sub

Previous post Next post
Up