2010-06-22 171 views
1

我有一個來自100個用戶的調查,我試圖計算一些統計數據。我調查中的相關字段如下所示:Excel公式:計算調查統計

Gender   Interests 
B1: Male   D1: Running, Snowboarding, Mountain Bikes 
B2: Male   D2: Programming, Running, Paintball 
B3: Female  D3: Bowling, Gymnastics 
B4: Male   D4: Rock Climbing, Running, 

我需要計算對「Running」感興趣的男性的百分比。文本將始終以字符串的形式出現在「正在運行」中,但它可能以不同的順序顯示。

這裏是我到目前爲止有:

=SUM(
    COUNTIF(
      D1:D100,ISNUMBER(
           SEARCH(D1:D100,"Running") 
      ) 
    ) 
) 

通知我沒有在男/女標準尚未因素。此表達式目前返回0.

任何幫助將不勝感激。

回答

2

一個簡單的方法來處理它將是打破你的計算一點。

在另一列中使用的公式是這樣的:

=IF(AND(B1="Male",ISNUMBER(SEARCH("Running",D1))),1,0) 

這會給你一個1大家誰是男性,有「暗戰」列爲興趣和0所有其他人。複製一下你的工作表,然後很容易計算出百分比,例如如果列是E:

=SUM(E1:E100)/100 
+0

這將工作,謝謝! – pws5068 2010-06-22 15:07:10

0

你可以用Excel和ADO做很多事情。

Dim cn As Object 
Dim rs As Object 
Dim sFile As String 
Dim sCn As String 
Dim sSQL As String 
Dim s As String, f As String 
Dim sa As Variant 
Dim i As Integer, c As Integer 
Dim r As Range 

''This is not the best way to refer to the workbook 
''you want, but it is very conveient for notes 
''It is probably best to use the name of the workbook. 

sFile = ActiveWorkbook.FullName 

sCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFile _ 
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" 

Set cn = CreateObject("ADODB.Connection") 
Set rs = CreateObject("ADODB.Recordset") 

cn.Open sCn 

sSQL = "SELECT interests " _ 
     & "FROM [Sheet1$] " 

rs.Open sSQL, cn, 3, 3 

With Worksheets("Sheet2") 
    s = rs.GetString(, , , ",") 
    sa = Split(s, ",") 

    c = 1 
    For i = 0 To UBound(sa) 
     Set r = .Range("a1:a" & c) 
     f = Trim(sa(i)) 
     If r.Find(f) Is Nothing Then 
      c = c + 1 
      .Cells(c, 1) = f 
     End If 
    Next 

    .Cells(1, 1) = "Interests" 
    .Cells(1, 2) = "Male" 
    .Cells(1, 3) = "Female" 

    For i = 2 To c 
     rs.Close 

     sSQL = "SELECT Gender, Count(Gender) As GNo " _ 
      & "FROM [Sheet1$] " _ 
      & "WHERE Interests Like '%" & .Cells(i, 1) & "%' " _ 
      & "GROUP BY Gender" 

     rs.Open sSQL, cn 

     Do While Not rs.EOF 
      If rs.Fields("Gender") = "Male" Then 
       .Cells(i, 2) = rs.Fields("GNo") 
      ElseIf rs.Fields("Gender") = "Female" Then 
       .Cells(i, 3) = rs.Fields("GNo") 
      End If 
      rs.MoveNext 
     Loop 

     Next 

End With 

''Tidy up 
rs.Close 
Set rs = Nothing 
cn.Close 
Set cn = Nothing 
End Sub 
+0

這似乎比接受的迴應稍微複雜一點:) – 2010-06-23 03:03:29

+0

它不依賴多餘的列,它計算每個輸入興趣的男性和女性的結果,而無需用戶選擇一個。它更復雜,因爲它超越了問題的一步。 – Fionnuala 2010-06-23 06:27:54

+0

這兩個答案都很有幫助,但在這個特殊情況下,我不介意有額外的專欄,所以爲了簡單起見,我和el chief一起去了。多謝你們! – pws5068 2010-06-23 12:38:12

1

你還應該測試一下,看看這個比例(喜歡跑步的男性的百分比)是不是僥倖。

您可以進行(皮爾遜或似然比)卡方檢驗,看看比例是否與預期不同。

你也可以做Fisher's Exact Test來查看例如性別之間的比例是否不同。