|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
摘抄于(https://zh-cn.extendoffice.com/d ... ns-with-header.html)
Sub Macro1()
'updateby Extendoffice
Dim xEndCol As Long
Dim I As Long
Dim xDel As Boolean
On Error Resume Next
xEndCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
If xEndCol = 0 Then
MsgBox "There is no data on """ & ActiveSheet.Name & """ .", vbExclamation, "Kutools for Excel"
Exit Sub
End If
Application.ScreenUpdating = False
For I = xEndCol To 1 Step -1
If Application.WorksheetFunction.CountA(Columns(I)) <= 1 Then
Columns(I).Delete
xDel = True
End If
Next
If xDel Then
MsgBox "All blank and column(s) with only a header row have now been deleted.", vbInformation, "Kutools for Excel"
Else
MsgBox "There are no Columns to delete as each one has more data (rows) than just a header.", vbExclamation, "Kutools for Excel"
End If
Application.ScreenUpdating = True
End Sub |
|