【问题标题】:Excel Macro for processing radio buttons by cell用于按单元格处理单选按钮的 Excel 宏
【发布时间】:2017-07-11 12:51:03
【问题描述】:

我在 excel 中创建一个宏来按单元格处理单选按钮,在调试和逐步进行的同时,代码似乎每次都忽略了我的单选按钮是否为真。任何指针将不胜感激!到目前为止,这是我所拥有的:(补充一点,我在多个单元格中有单选按钮,我在此处更改了代码,以便可以在单个单元格上进行测试)

Sub RadioController()

Dim total As Integer
Dim pass As Integer
Dim fail As Integer
Dim rng As Range, cell As Range
Set rng = Range("L4")

    For Each cell In rng

        If radYes = True Then
            pass = pass + 1
            total = total + pass
        Else
            fail = fail + 1
        End If

    Next cell

    Range("K4") = total

End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    所以我猜你正在使用 Active-X-Controls。您必须使用Worksheets 方法来调用您的OptionButton。因此,如果 Button 位于第一个 Worksheet 上,它将是:

    ...
        For Each cell In rng
    
            If Worksheets(1).radYes = True Then
                pass = pass + 1
                total = total + pass
            Else
                fail = fail + 1
            End If
    
        Next cell
    ...
    

    否则它会将radYes 作为变量处理。如果你使用F8 并将鼠标悬停在它上面,它应该说它是空的。

    【讨论】:

    • 感谢您的回复!我使用常规表单控件,我无法选择 activeX 组件(当我单击它们时,单选按钮不会选中)
    猜你喜欢
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    相关资源
    最近更新 更多