简体   繁体   English

使用复选框Excel VBA调用子

[英]calling a sub using checkboxes excel vba

I'm trying to call a sub using this code 我正在尝试使用此代码调用子

If CheckBox2 = True Then Call Qorep

Heres the sub : 继承人子:

Public Sub Qorep()

For i = 0 To cap
    Hoja9.Cells(i + 2, 3).Value = Empty
    array_Qorep(i, 0) = Hoja1.Range("B" & i + 2)

    Select Case Hoja9.Cells(3, 5)
    Case Is > 0
    If array_Qorep(i, 0) < Hoja9.Cells(3, 5) Then Hoja9.Cells(i + 2, 3) = array_Qorep(i, 0)
    End Select

    Select Case Hoja9.Cells(3, 4)
    Case Is > 0
    If array_Qorep(i, 0) > Hoja9.Cells(3, 4) Then Hoja9.Cells(i + 2, 3) = array_Qorep(i, 0)
    End Select
    If Hoja9.Cells(i + 2, 3) = Empty Then Hoja9.Cells(i + 2, 3) = "#N/A"
    Next
End Sub

The problem is that with the checkbox checked it doesn't do anything, is there a problem trying to call the sub? 问题在于选中此复选框后,它什么也不做,尝试调用该子项是否存在问题? im a beginner and i might not be able to see whats wrong, any help? 我是初学者,我可能看不到有什么问题,有帮助吗?

In the worksheet you need 在工作表中,您需要

 Private Sub  CheckBox2_Click()

       If CheckBox2 = True Then Call Qorep

   End Sub

If your sub is not in the same worksheet then you need to use Modulename.Qorep 如果您的子项不在同一工作表中,则需要使用Modulename.Qorep

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM