'愚直にドント方式百分率配分をどーんとプログラムしてみました
Public Sub どーんと実行()
'dont(入力データ範囲,出力データ範囲)
Call donto(Range("A1:C1"), Range("A2:C2"))
End Sub
'入力データは100分率
'dont(入力データ範囲,出力データ範囲)
Public Sub donto(s As Range, d As Range)
Dim data() As Double, count() As Integer, dataKind As Integer
Dim i As Integer, j As Integer, x As Range, maxV As Double, maxI As Integer, sum As Integer
dataKind = s.count 'データの分類数
ReDim data(100, dataKind)
ReDim count(dataKind)
i = 0
For Each x In s
i = i + 1
count(i) = 0
data(0, i) = x.Value
Next
For i = 1 To 100
For j = 1 To dataKind
data(i, j) = data(0, j) / i 'ドント表の作成
Next
Next
Do While True
maxV = 0#
For j = 1 To dataKind '最大値を求める
If data(count(j) + 1, j) > maxV Then '0%のデータは無い
maxV = data(count(j) + 1, j)
maxI = j
End If
Next
count(maxI) = count(maxI) + 1 '最大値の件数を1増やす
sum = 0
For j = 1 To dataKind '合計を求める
sum = sum + count(j)
Next
If sum = 100 Then Exit Do
Loop
'出力に設定
i = 0
For Each x In d
i = i + 1
x.Value = count(i)
Next
End Sub
お礼
ありがとうございます! 試す時間を少しください。