用于检查最小的

时间:2017-07-19 14:27:57

标签: excel vba checkbox

我正在寻找解决问题的方法。我有这个巨大的excel表(这里重要的是它由超过700行组成),我想制作我所谓的“大复选框”来检查“小复选框”click here to see a picture which explains it better

事实是,我有大量的数据,我无法确切地知道有多少小复选框将链接到一个大复选框,因此我必须创建一个宏来为每个复选框执行链接。我已经编写了一个自动创建大小复选框的宏,所以现在我只需要创建链接。

我创建了“链接”宏,它适用于小型电子表格。但是在我的700行电子表格中,当我检查一个大的复选框来检查链接到它的小复选框时,程序需要20到30秒。

我认为我没有以正确的方式做到这一点:例如,为了区分大的复选框和小的复选框,我将它们命名为CBX_“复选框的范围是”而不是cbx __“复选框的单元格范围”。

请你帮我制作一个更快的程序,真的不应该复杂,只是因为我对复选框的使用感到不舒服。

Sub HideLinkedChkV3()
Application.ScreenUpdating = False
Dim bigchk As CheckBox
Dim chk As CheckBox
Dim lenrange As Integer
Dim diff As Long
Dim diff1 As Integer
Dim diff2 As Integer
Dim rgr_start As Integer
Dim rgr_end As Integer
'rgr start and end are the rows where begin and end the little checkboxes
Dim rgc As Integer
'rgc is the column where begin the little checkboxes
rgr_start = 7
rgr_end = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
rgc = 2
lenrange = Range(Cells(rgr_start, rgc), Cells(rgr_end, rgc)).Rows.Count
For Each bigchk In ActiveSheet.CheckBoxes
'bigchk is a checkbox which checks multiple little checkboxes
If Left(bigchk.Name, 3) = "CBX" Then
'here we're making sure that the checkbox is a big check
    If bigchk.Value = Checked Then
        For Each chk In ActiveSheet.CheckBoxes
            diff1 = CInt(Right(chk.Name, Len(chk.Name) - 5))
            diff2 = CInt(Right(bigchk.Name, Len(bigchk.Name) - 5))
            diff = diff1 - diff2
            If Left(chk.Name, 3) = "cbx" And diff < lenrange And diff >= 0 Then
            'here we are making sure that the checkbox is a little checkbox and that it belongs to the big checkbox on its left
                chk.Value = Checked
            End If
        Next chk
    Else
        For Each chk In ActiveSheet.CheckBoxes
            diff1 = CInt(Right(chk.Name, Len(chk.Name) - 5))
            diff2 = CInt(Right(bigchk.Name, Len(bigchk.Name) - 5))
            diff = diff1 - diff2
            If Left(chk.Name, 3) = "cbx" And diff < lenrange And diff >= 0 Then
                chk.Value = Unchecked
            End If
        Next chk
    End If
End If
Next bigchk
Application.ScreenUpdating = True
End Sub

0 个答案:

没有答案