VBA Application.WorksheetFunction.Median
11.11.2014 14:45:27
Lolaley
Ich wollte mir gern von untereinandergeschriebenen Daten pro Monat (hier jetzt nur die mit 31 Tagen) die Mediane ausrechnen lassen. Dabei kommt jetzt aber immer die Fehlermeldung:
"Eigenschaft des WorksheetFunction-Objektes kann nicht zugeordnet werden"
Ich schätze mal, die Deklarationsvariable ist nicht korrekt dimensioniert. Als Variant funktioniert es aber beispielsweise auch nicht. Was sollte ich nehmen, bzw. was ist hier der Fehler?
Sub Median()
Dim A As Date
Dim Row1, Row2, RowMax As Integer
Dim Col1, Col2 As Integer
Dim sum, Med, MW As Double
Dim i, j As Integer 'i=Jahr , j=Monat
Dim ArrTxt As Variant
Dim MyArray(1 To 300, 1 To 100) As Variant
Dim wks1 As Worksheet
Set wks1 = ActiveSheet
RowMax = wks1.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For Row1 = 2 To RowMax + 1
If Month(DateValue(Cells(Row1, 1))) = 1 Or Month(DateValue(Cells(Row1, 1))) = 3 Or Month( _
DateValue(Cells(Row1, 1))) = 5 Or Month(DateValue(Cells(Row1, 1))) = 7 Or Month(DateValue(Cells(Row1, 1))) = 8 Or Month(DateValue(Cells(Row1, 1))) = 10 Or Month(DateValue(Cells(Row1, 1))) = 12 Then
MW = Application.WorksheetFunction.Average("B" & Row1 & ":B" & Row1 + 30)
Med = Application.WorksheetFunction.Median("B" & Row1 & ":B" & Row1 + 30)
Row1 = Row1 + 31
End If
Next Row1
End Sub
Vielen Dank im voraus!