Excel VBA根据下拉列表选择和复选框选择隐藏列

55ooxyrt  于 2023-02-17  发布在  其他
关注(0)|答案(1)|浏览(189)

是否有可能将下面的两个代码组合起来,以便在选中复选框且D11单元格具有特定选择时,基于这两个选择隐藏列?

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$D$11" Then
        If Target.Value = "A" Or Target.Value = "C" Then
           Sheets("Worksheet").Columns("BL:CH").Hidden = True
        ElseIf Target.Value = "C" Then
Sheets("Worksheet").Columns("BL:BY").Hidden = False
        End If
    End If
End Sub

Private Sub CheckBox1_Click()
    Sheets("Worksheet").Columns("BZ:CH").Hidden = Not Me.CheckBox1.Value  (TO UNHIDE SPECIFIC COLUMS ONLY WHEN CHECKED)

End Sub
t2a7ltrp

t2a7ltrp1#

这就是我要做的谢谢

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$11" Then
    If Target.Value = "A" Or Target.Value = "B" Then
        Sheets("Worksheet").Columns("BL:CH").Hidden = True
    ElseIf Target.Value = "C" And Not Me.CheckBox1.Value Then
        Sheets("Worksheet").Columns("BL:BY").Hidden = False
    ElseIf Target.Value = "C" And Me.CheckBox1.Value Then
        Sheets("Worksheet").Columns("BL:BY").Hidden = True
        Sheets("Worksheet").Columns("BZ:CH").Hidden = False
    End If
 End If
End Sub

相关问题