VBA如何仅勾选符合条件的复选框:仅操作E列非False对应复选框
修改后的VBA代码
Sub SelectAllSubSector() Dim cBoxSector As CheckBox Dim targetRow As Long For Each cBoxSector In Worksheets("Input attractivite").CheckBoxes ' 仅筛选C5:C150区域内的复选框 If Not Intersect(cBoxSector.TopLeftCell, Range("C5:C150")) Is Nothing Then targetRow = cBoxSector.TopLeftCell.Row ' 新增判断:对应E列同行单元格值不为False,且排除主控制复选框Check Box 3 If cBoxSector.Name <> ActiveSheet.CheckBoxes("Check Box 3").Name And Cells(targetRow, "E").Value <> False Then cBoxSector.Value = ActiveSheet.CheckBoxes("Check Box 3").Value End If End If Next cBoxSector End Sub
改动说明
- 新增
targetRow变量用于获取当前复选框所在的行号 - 在原有判断条件中新增逻辑:仅当复选框对应行的E列单元格值不等于
False时,才会同步主复选框(Check Box 3)的勾选状态 - 原有筛选C5:C150区域、排除主控制复选框的逻辑完全保留,不影响原有生效范围
内容的提问来源于stack exchange,提问作者Circus_beta
相关产品推荐
相关产品推荐

