我有一个包含许多列(包括自动过滤的标题)的表,其中一些列只有标题,该列内没有其他数据。我想从我的命名表中删除这些列。
问问题
107 次
2 回答
0
这是给你的代码,下次尝试编写代码
Public Sub teste()
Call DeleteTableColumnNull("table")
End Sub
Public Sub DeleteTableColumnNull(ByVal TableObjectName As String)
Dim table As ListObject
Dim st As Worksheet
Dim cols As Range
Dim col As Range
Dim rows As Range
Dim row As Range
For Each st In ThisWorkbook.Worksheets
If tableExistInThisSheet(st, TableObjectName) Then
Set table = st.ListObjects(TableObjectName)
For Each col In table.Range.Columns
If Application.WorksheetFunction.CountA(col) = 1 Then
col.Delete
End If
Next col
End If
Next
End Sub
Public Function tableExistInThisSheet(st As Worksheet, TableObjectName As String) As Boolean
On Error GoTo f
Dim tb As ListObject
Set tb = st.ListObjects(TableObjectName)
tableExistInThisSheet = True
Exit Function
f:
End Function
于 2019-04-22T19:28:29.017 回答