Function GemWindRichting(Richtingen As Range)
'deze functie werkt met tekstinvoer (bv NNO) en met Graden 0 tot 360)
'of met combinatie dus in de ene cel staat bv NNO en inde andere staat bv 325
Dim Tekst, R As Range, TotSin As Double, TotCos As Double, Hoek As Double, Teller As Integer, TempR As String
Tekst = Array("N", 0, "NNO", 22.5, "NO", 45, "ONO", 67.5, _
"O", 90, "OZO", 112.5, "ZO", 135, "ZZO", 157.5, _
"Z", 180, "ZZW", 202.5, "ZW", 225, "WZW", 247.5, _
"W", 270, "WNW", 292.5, "NW", 315, "NNW", 337.5)
For Each R In Richtingen
If IsNumeric(R) Then
Hoek = R / 180 * WorksheetFunction.Pi
Else
TempR = UCase(R)
For Teller = 0 To UBound(Tekst) Step 2
If Tekst(Teller) = TempR Then
Hoek = Tekst(Teller + 1) / 180 * WorksheetFunction.Pi
Exit For
End If
Next Teller
End If
If Teller > UBound(Tekst) Then GemWindRichting = "fout": Exit Function
TotSin = TotSin + Sin(Hoek)
TotCos = TotCos + Cos(Hoek)
Next R
If TotSin = 0 And TotCos = 0 Then GemWindRichting = "nul": Exit Function
GemWindRichting = WorksheetFunction.Atan2(TotCos, TotSin) * 180 / WorksheetFunction.Pi
End Function