大checkbox检查最小的一个

我正在寻找解决我的问题。 我有这个巨大的excel表(这里最重要的是它由700多行组成),我想使我所谓的“大checkbox”来检查“小checkbox” 点击这里看到一个图片,解释它更好 。

事实是,我有大量的数据,我不知道有多less个checkbox将链接到一个大的checkbox,所以我必须做一个macros来做每个checkbox的链接。 我已经写了一个macros自动创build大和小checkbox,所以现在我只是创build链接。

我创build了“链接”macros,它在一个小电子表格上工作。 但在我的700行电子表格中,当我检查一个大的checkbox来检查链接到它的小checkbox时,程序需要20到30秒。

我认为我没有正确的做法:例如,为了区分大checkbox和小checkbox,我将它们命名为CBX_“checkbox所在的单元格的范围”而不是“checkbox所在的单元格的范围”。

请你能帮我做一个更快的程序,真的不应该是复杂的,只是我不太喜欢使用checkbox。

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