Skip to content

Instantly share code, notes, and snippets.

@lunark
Created December 21, 2012 06:40
Show Gist options
  • Save lunark/4351078 to your computer and use it in GitHub Desktop.
Save lunark/4351078 to your computer and use it in GitHub Desktop.
VBAマクロ向け関数。とりあえず説明は後で書きます。
Public Function GenderInterpolation(strN As String, strR As String, strGM As String, strGF As String, strN範囲 As String, strR範囲 As String, strG範囲 As String)
Dim intM As Long
Dim intF As Long
Dim intMax As Integer
Dim intMin As Integer
'----------------------------------------------
'名簿の中にある苗字と条件で、性別がどちらかを推定する
'----------------------------------------------
'
'まず、指定された名前の男性・女性数を出す
intM = Evaluate("SUMPRODUCT(((" & strN範囲 & ")=""" & strN & """)*((" & strR範囲 & ")=""" & strR & """)*((" & strG範囲 & ")=""" & strGM & """))")
intF = Evaluate("SUMPRODUCT(((" & strN範囲 & ")=""" & strN & """)*((" & strR範囲 & ")=""" & strR & """)*((" & strG範囲 & ")=""" & strGF & """))")
'合計が1以下の場合、ふりがなと性別の男女比で出す
'If intM + intF > 20 Then
'intM = Evaluate("SUMPRODUCT(((" & strR範囲 & ")=""" & strR & """)*((" & strG範囲 & ")=""" & strGM & """))")
'intF = Evaluate("SUMPRODUCT(((" & strR範囲 & ")=""" & strR & """)*((" & strG範囲 & ")=""" & strGF & """))")
'End If
intMax = intM + intF
intMin = 1
If Int((intMax - intMin + 1) * Rnd + intMin) > intM Then
GenderInterpolation = strGF
Else
GenderInterpolation = strGM
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment