需要checkbox来隐藏和取消隐藏空行

我有以下几点,我试图隐藏空白的行,并带回一个CHECKBOX,以便在需要时添加行。 我不想删除它们。

Sub Sample() Dim i As Long Dim DelRange As Range On Error GoTo Whoa Application.ScreenUpdating = False For i = 1 To 250 If Application.WorksheetFunction.CountA(Range("A" & i & ":" & "L" & i)) = 0 Then If DelRange Is Nothing Then Set DelRange = Rows(i) Else Set DelRange = Union(DelRange, Rows(i)) End If End If Next i If Not DelRange Is Nothing Then DelRange.Delete shift:=xlUp LetsContinue: Application.ScreenUpdating = True Exit Sub Whoa: MsgBox Err.Description Resume LetsContinue End Sub 

  1. 在function区的“开发人员”选项卡上的“控件”部分中,单击“插入”下拉菜单,然后单击“ActiveX控件”部分中的checkbox控件(而不是“窗体控件”部分中的checkbox控件)

  2. 点击您希望checkbox出现的表单

  3. 双击该checkbox,并在自动生成的CheckBox1_Click方法中(假设这是表单上的第一个checkbox),请调用您的方法: Sample

  4. Sample方法中,执行下面的Replace

  5. 在function区的“开发人员”选项卡上的“控件”部分,单击“devise模式”button以closuresdevise模式(否则,您将无法检查并取消选中您的checkbox)

replace这个:

 If Not DelRange Is Nothing Then DelRange.Delete shift:=xlUp 

有了这个,“Sheet1”是您的工作表的名称,“CheckBox1”是您的checkbox的名称:

 If Not DelRange Is Nothing Then DelRange.Rows.Hidden = Sheets("Sheet1").CheckBox1.Value