无效限定符 - 对于两组布尔条件

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

您好,我是 Excel VBA 新手,尝试告诉 VBA 自动计算(如果我的自动计算复选框被选中)。 如果选择了自动计算复选框,请检查是否选择了 RectanglePerp 复选框。如果选择 RectanglePerp,则使用第一个公式进行计算,否则使用第二个公式进行计算。如果未选择自动计算,则需手动键入值。不知道我在这里做错了什么。

更新了VBA:

 If chkAutoCal.Value = True Then
    If chkRectanglePerp.Value = True Then
        ActiveCell.Offset(0, 11).Value = 2 * ActiveCell.Offset(0, 9).Value + ActiveCell.Offset(0, 2).Value + (ActiveCell.Offset(0, 8).Value - 1) * ActiveCell.Offset(0, 5).Value
    Else
        ActiveCell.Offset(0, 11).Value = 2 * ActiveCell.Offset(0, 10).Value + ActiveCell.Offset(0, 2).Value + (ActiveCell.Offset(0, 8).Value - 1) * ActiveCell.Offset(0, 5).Value
    End If
 Else
    ActiveCell.Offset(0, 11).Value = txtPileCapBreath.Value
 End If
 ActiveCell.Offset(0, 11).HorizontalAlignment = xlCenter
 ActiveCell.Offset(0, 11).VerticalAlignment = xlCenter
 ActiveCell.Offset(0, 11).NumberFormat = Range("N4").NumberFormat

以前的VBA:

 Dim chkAutoCal As Boolean
 Dim chkRectanglePerp As Boolean
 
 If chkAutoCal.Value = True Then
     If chkRectanglePerp = True Then
        ActiveCell.Offset(0, 11).Value = txtEndDist.Value + txtPileDiameter.Value + (txtRowNo.Value - 1) * ActiveCell.Offset(0, 5).Value + txtEndDist.Value
    Else
        ActiveCell.Offset(0, 11).Value = txtEdgeDist.Value + txtPileDiamter.Value + ((txtPileNo.Value / txtRowNo.Value) - 1) * ActiveCell.Offset(0, 5).Value + txtEdgeDist.Value
    End If
 Else
    ActiveCell.Offset(0, 11).Value = txtPileCapBreath.Value
    ActiveCell.Offset(0, 11).HorizontalAlignment = xlCenter
    ActiveCell.Offset(0, 11).VerticalAlignment = xlCenter
    ActiveCell.Offset(0, 11).NumberFormat = Range("N4").NumberFormat
excel vba boolean-logic
1个回答
0
投票

评论总结:

  • 删除两条

    Dim
    线。
    chkAutoCal
    chkRectanglePerp
    都是文件中的控件。
    Dim
    语句将它们声明为变量,导致
    chkAutoCal
    .Value 出现无效限定符错误。
    Boolean
    变量没有
    Value
    属性。

  • 如果

    txtPileCapBreath
    不在活动工作表上,您将收到错误 424。请使用工作表对象限定所有控件。例如。
    Sheets("YourSheetName").txtPileCapBreath.Value

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.