如何基于用户表单组合框响应动态计算分数

问题描述 投票:0回答:1

我有一个带有7个组合框的用户窗体,这些组合框具有YesNoPartiallyN/A选项。根据每个框的响应,我有一个填充总分的文本框。

Yes = 1Partially = 0.5No = 0NA = 0

我有基于组合框响应进行计算的代码,如果我简单地除以总框数(7),则计算得出,但是并非所有表格都会有7个响应(NA是一个选项,但基本上不计入或反对他们)。因此,我需要弄清楚如何将总分除以总答复。我敢肯定这是超级容易的,但我并没有努力找出来。

这是我当前那里没有给我正确%的代码

TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
Private Sub CommandButton1_Click()

Dim c As Control, nYes As Long, nPartial As Long, nNo As Long


For Each c In Me.Controls
    If TypeName(c) = "ComboBox" Then
        If c.Value = "Yes" Then nYes = nYes + 1
        If c.Value = "Partially" Then nPartial = nPartial + 1
        If c.Value = "No" Then nNo = nNo + 1
    End If
Next c

TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
End Sub

例如-6是,1 NA = 100%,5是,1部分是1 NA = 92%

excel vba userform
1个回答
1
投票

您也应该算NA(我想加上一些括号)

Private Sub CommandButton1_Click()

Dim c As Control, nYes As Long, nPartial As Long, nNo As Long, nNA As Long
nYes = 0
nPartial = 0
nNo = 0
nNA = 0


For Each c In Me.Controls
    If TypeName(c) = "ComboBox" Then
        If c.Value = "Yes" Then nYes = nYes + 1
        If c.Value = "Partially" Then nPartial = nPartial + 1
        If c.Value = "No" Then nNo = nNo + 1
        If c.Value = "NA" Then nNA = nNA + 1
    End If
Next c

TXTScore = Format((nYes + nPartial * 0.5) / (nYes + nPartial + nNo + nNA), "Percent")
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.