|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
摘抄于(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 |
|