Excel Userform-有没有办法让标签根据来自组合框的 7 的 "Yes" 或 "Partially" 响应计算分数?
Excel Userform- Is there a way to have a label calculate a score based on the "Yes" or "Partially" responses of 7 from comboboxs?
我有一个 Excel 用户表单,它有 7 个组合框,选项有 N/A、是、否和部分。我想根据表单标签中每个组合框的响应创建一个总分,该标签将在更新框或单击按钮时计算(真的没关系)。
是 = 1
部分 = 0.5
为了获得分数,我还需要对是和部分结果进行计数,因为分数将是是和 Partially/7.
的总和
不过,我似乎无法获得用于更新任何基本结果的标签。
我已经尝试寻找已经存在的代码,但我发现的所有内容都引用了实际的 excel worksheet/cells 而不是用户表单中的直接结果,或者他们正在添加实际数字而不是转换将文本结果转换为要计算的数字。
这个嵌套的 if 语句只是我最近的一次尝试,试图让组合框之一填充到我的标签中,但没有成功。
Private Sub Score_Change()
If CBCoverage.Value = "Yes" Then LBLCYes = 1
Else: LBLCYes = 0
If CBCoverage.Value = "Partially" Then LBLCPartially = 0.5
Else: LBLCPartiall = 0
End If
End If
End If
End Sub
我不指望你为我写完整的东西,但如果你能帮我看看我在这里做错了什么,那就太棒了!
我的组合框被命名为:
CBC报道
CB调查
CB金融
CBAutoPD
CBE评估
CB文档
CB通讯
我将此代码附加到表单的按钮上。它循环遍历表单上的每个组合框,所以如果有一些你想排除循环将需要修改。
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial 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
End If
Next c
MsgBox "There were " & nYes & " Yes, and " & nPartial & " Partial answers."
End Sub
您可以根据 nYes
和 nPartial
计算总加权分数,例如
nYes + nPartial * 0.5
我有一个 Excel 用户表单,它有 7 个组合框,选项有 N/A、是、否和部分。我想根据表单标签中每个组合框的响应创建一个总分,该标签将在更新框或单击按钮时计算(真的没关系)。 是 = 1 部分 = 0.5 为了获得分数,我还需要对是和部分结果进行计数,因为分数将是是和 Partially/7.
的总和不过,我似乎无法获得用于更新任何基本结果的标签。
我已经尝试寻找已经存在的代码,但我发现的所有内容都引用了实际的 excel worksheet/cells 而不是用户表单中的直接结果,或者他们正在添加实际数字而不是转换将文本结果转换为要计算的数字。
这个嵌套的 if 语句只是我最近的一次尝试,试图让组合框之一填充到我的标签中,但没有成功。
Private Sub Score_Change()
If CBCoverage.Value = "Yes" Then LBLCYes = 1
Else: LBLCYes = 0
If CBCoverage.Value = "Partially" Then LBLCPartially = 0.5
Else: LBLCPartiall = 0
End If
End If
End If
End Sub
我不指望你为我写完整的东西,但如果你能帮我看看我在这里做错了什么,那就太棒了! 我的组合框被命名为: CBC报道 CB调查 CB金融 CBAutoPD CBE评估 CB文档 CB通讯
我将此代码附加到表单的按钮上。它循环遍历表单上的每个组合框,所以如果有一些你想排除循环将需要修改。
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial 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
End If
Next c
MsgBox "There were " & nYes & " Yes, and " & nPartial & " Partial answers."
End Sub
您可以根据 nYes
和 nPartial
计算总加权分数,例如
nYes + nPartial * 0.5