通过CBool​​列隐藏,无法正常工作

时间:2014-11-15 00:21:56

标签: excel vba

有谁知道,为什么这段代码不礼貌并且用未知规则隐藏我的列?

Sub EmptyCol()
Call UnlockS

Dim Table As Range:     Set Table = Range("O_List")
Dim Col As Range
Dim Emp As Boolean

Dim c As Long
'Table.Columns.hide = False
With Table
    For c = 4 To .Columns.Count
    Set Col = .Columns(c)
        If (Application.CountIf(Col, "")) = (.Rows.Count) Then Emp = True
        .Columns(c).EntireColumn.Hidden = CBool(Emp)

    Next c
End With

Call L_ORDER
End Sub

V1

    for c = 1 to .columns.count
        .columns(c).entirecolumn.hidden = not cbool(application.counta(.columns(c)))

我之前发布的编辑代码,但现在我知道它还没有用。它也隐藏不是空白的colums。谢谢你的帮助。

2 个答案:

答案 0 :(得分:1)

Sub EmptyCol()
    Call UnlockS

    Dim Table As Range:     Set Table = Range("O_List")
    Dim Col As Range
    Dim Emp As Boolean

    Dim c As Long
    Table.Columns.Hidden = False
    With Table
        For c = 4 To .Columns.Count
            .Columns(c).EntireColumn.Hidden = _
                        (Application.CountA(.Columns(c)) = 0)
         Next c
    End With

    Call L_ORDER
End Sub

答案 1 :(得分:1)

我没看到你把Emp设置为假的地方。一旦它找到了if的肯定结果,它就会隐藏那一点上的每一列。