P
Pierre
Using ExcHi All,
I am trying to calculate the area of a polygon, (using a function
kindly posted by somebody on this newsgroup) .
I am not very familiar with the required syntax ofarrays and
functions. The function should be executed under a forms commandbutton
as follows:
Sub area()
Range("AD5:AE5").Select
Range("a5").Value = AreaByCoordinates((Selection())) ' THIS IS WHERE
THE PROBLEM LIES
End Sub
Function AreaByCoordinates(Xcoord() As Double, _
Ycoord() As Double) As Double
Dim I As Long
Dim Xold As Double
Dim Yold As Double
Dim Yorig As Double
Dim ArrayUpBound As Long
ArrayUpBound = UBound(Xcoord)
Xold = Xcoord(ArrayUpBound)
Yorig = Ycoord(ArrayUpBound)
Yold = 0#
For I = LBound(Xcoord) To ArrayUpBound
x = Xcoord(I)
y = Ycoord(I) - Yorig
AreaByCoordinates = AreaByCoordinates + _
(Xold - x) * (Yold + y)
Xold = x
Yold = y
Next
AreaByCoordinates = Abs(AreaByCoordinates) / 2
End Function
I get the message "Type mismatch: Array or userdefined type expected"
(Using Excel 2003)
Can anybody assist please?
Thanks very much.
Pierre Henning
I am trying to calculate the area of a polygon, (using a function
kindly posted by somebody on this newsgroup) .
I am not very familiar with the required syntax ofarrays and
functions. The function should be executed under a forms commandbutton
as follows:
Sub area()
Range("AD5:AE5").Select
Range("a5").Value = AreaByCoordinates((Selection())) ' THIS IS WHERE
THE PROBLEM LIES
End Sub
Function AreaByCoordinates(Xcoord() As Double, _
Ycoord() As Double) As Double
Dim I As Long
Dim Xold As Double
Dim Yold As Double
Dim Yorig As Double
Dim ArrayUpBound As Long
ArrayUpBound = UBound(Xcoord)
Xold = Xcoord(ArrayUpBound)
Yorig = Ycoord(ArrayUpBound)
Yold = 0#
For I = LBound(Xcoord) To ArrayUpBound
x = Xcoord(I)
y = Ycoord(I) - Yorig
AreaByCoordinates = AreaByCoordinates + _
(Xold - x) * (Yold + y)
Xold = x
Yold = y
Next
AreaByCoordinates = Abs(AreaByCoordinates) / 2
End Function
I get the message "Type mismatch: Array or userdefined type expected"
(Using Excel 2003)
Can anybody assist please?
Thanks very much.
Pierre Henning