VBA + 复选框 + 自动过滤



我在 excel 中有一个带有自动过滤器的列表,其中每一行都有一个复选框。

我制作了一个带有宏的按钮来选择所有复选框。这工作正常。但是当我过滤行时,我的"全选"必须只选中可见的复选框

使用我的代码,它仍然选择所有复选框。有人有解决这个问题的想法吗?

我的代码:

  Sub SelectAll()
  Dim chk As CheckBox
  If Worksheets("Summary").FilterMode = True Then
    MsgBox "Filter mode is on"      
  Else
    MsgBox "Filter mode is off"
    For Each chk In Worksheets("Summary").CheckBoxes
      chk.Value = Checked
    Next
  End If
End Sub

提前致谢

我认为您的复选框被过滤隐藏了。

这可能会在您的循环中有所帮助:

Dim chkRng As Range
Set chkRng = chk.TopLeftCell
Let addr = chkRng.Address ' for debugging to verify the cell the checkbox is associated with
Dim visr As Range
Set visr = chkRng.SpecialCells(xlCellTypeVisible)
Set ans = Intersect(visr, chkRng)
If Not ans Is Nothing Then
   MsgBox ("visible")
End If

最新更新