I am trying to make a dynamic frequency table in VBA using the countif formula.
The general idea is to:
1) find the highest and lowest values in arange using "max" and "min" formula.
2) Create 30 intervals using interval (max-min)/30.
3) Use excelfunction count if to count the number observations within each interval.
I am quite new to VBA and programming in general. However has made the following attempt. The problem is, however, that the code only returns the value 0. Thank You
The general idea is to:
1) find the highest and lowest values in arange using "max" and "min" formula.
2) Create 30 intervals using interval (max-min)/30.
3) Use excelfunction count if to count the number observations within each interval.
I am quite new to VBA and programming in general. However has made the following attempt. The problem is, however, that the code only returns the value 0. Thank You
Code:
Sub distribution()
Dim low As Single
Dim high As Single
Dim rng As Range
Dim stp As Single
Set rng = Sheets("Aktivandel").Range("B3", Range("B3").End(xlDown))
low= WorksheetFunction.Min(rng)
high = WorksheetFunction.Max(rng)
stp = (high - low) / 30
For i = low To high Step stp
For j = 1 To 30
a = WorksheetFunction.CountIf(rng, ">"&(i+stp)) - WorksheetFunction.CountIf(rng, "<"& i)
i = i + stp
Sheets("Summary").Range("A1").Offset(j, o) = a
Next j
Next i
End Sub