Question : VBA Function with Array Parameter not working

I am new to VBA and functions.  I am working on (learning) how to work with Arrays.  I'm trying to do something simple (for now; I've commented out what I was originally trying to do)- use an array as a parameter and return the value in the second (2nd) position.  What am I doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Function GetSum(InRange2) As Long

 ' SumArray
    ' This sums the elements of Arr and returns
    ' the total.
  
    Dim N As Long
    Dim Total As Long
    Dim MaxItems As Integer
    MaxItems = UBound(InRange2)
    'For N = (InRange2) To UBound(InRange2)
     '   Total = Total + InRange2(N)
    'Next N
    GetSum = InRange2(2).Value
    'GetSum = Total

End Function

Answer : VBA Function with Array Parameter not working

OR
1:
2:
3:
4:
5:
6:
7:
8:
9:
Public Function GetSum(ByVal r As Range) As Integer
  Dim i, j As Integer
  For i = 1 To r.Count
    If IsNumeric(r.Cells(i).Value) Then
       j = j + r.Cells(i).Value
    End If
  Next i
  GetSum = j
End Function
Random Solutions  
 
programming4us programming4us