【问题标题】:How to divide and get the percentage of the value of two different textboxes in userform?如何划分和获取用户窗体中两个不同文本框的值的百分比?
【发布时间】:2019-09-06 02:04:27
【问题描述】:

我是 VBA 新手,目前正在为我们的一个 LOB 创建评估表。我很难理解我当前的代码有什么问题,它不会划分两个文本框的值。当我试图将一个文本框的值除以一个数字时,它会起作用。但这不是我想要的,因为文本框中的值取决于表单问题(有些问题是不适用的)。

我已经尝试了下面的代码,但它不起作用。

Sub CusImp2_div()

CusImp2.Value = Val(CusImp1.Value) / Val(CusImp3.Value)
CusImp2.Value = Format(Me.CusImp2.Value, "0.00%")

End Sub

the source of the values are...

Sub custotal_mulcal()

Me.CusImp1.Value = Val(CustTotal1.Value) * (0.33)

Me.CusImp1.Value = Application.WorksheetFunction.Round(Val(CusImp1.Value), 2)

Me.CusImp3.Value = Val(CustTotal2.Value) * (0.33)

Me.CusImp3.Value = Application.WorksheetFunction.Round(Val(CusImp3.Value), 2)
End Sub

当我运行公式并激活用户窗体时,我遇到了调试问题,我似乎不知道该怎么做。

我希望输出是输出的百分比。 96%

我真的希望有人可以帮助我解决这个问题,我真的很沮丧,因为我在截止日期之后运行。

谢谢!

【问题讨论】:

  • “它不起作用”是否意味着您遇到了错误?错误是什么,在哪一行?
  • 嗨。我在 CusImp2.Value = Val(CusImp1.Value) / Val(CusImp3.Value) 上遇到错误,我尝试一遍又一遍,但我不明白为什么我会收到错误
  • 您遇到的错误是什么,发生这种情况时 CusImp1 和 CusImp3 的值是多少?
  • @Stacy771991 是用户表单还是模块中的子项?
  • 嗨。子用于用户表单。 CusImp1 的值是一个临界值的总分,而 CusImp1 是该临界值的可用总分值。有些问题有时会得到 NA,公式也应该灵活。

标签: excel vba userform


【解决方案1】:

'我想我找到了这个问题的答案。我在 Youtube 中找到了下面的公式,现在表格运行良好。唯一的限制是即使我尝试更改答案,百分比也不会改变(我将研究如何解决这个问题)..

Sub CusImp2_div()

Dim a As Double
Dim b As Double
Dim answer As Double

a = CusImp1.Value
b = CusImp3.Value
answer = a / b

If b <> 0 Then
answer = a / b

End If

Me.CusImp2.Value = answer

Me.CusImp2.Value = Format(Me.CusImp2.Value, "0.00%")

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多