|
楼主 |
发表于 2018-8-30 10:25:44
|
显示全部楼层
Private Sub CommandButton1_Click()
MsgBox ("消息框")
End Sub
Private Sub CommandButton2_Click()
Delete_Empty_Rows
End Sub
Private Sub CommandButton3_Click()
Delete_Empty_Columns
End Sub
'Option Explicit
'删除所选区空行
Sub Delete_Empty_Rows()
Dim rnArea As Range
Dim lnLastRow As Long, i As Long, j As Long
Application.ScreenUpdating = False
lnLastRow = Selection.Rows.Count
Set rnArea = Selection
If rnArea.Rows.Count <= 1 Then
MsgBox ("请先选中一块多行包含文字的区域")
GoTo LastLine
End If
j = 0
For i = lnLastRow To 1 Step -1
If Application.CountA(rnArea.Rows(i)) = 0 Then
rnArea.Rows(i).Delete
j = j + 1
End If
Next i
If (lnLastRow - j) > 0 Then
rnArea.Resize(lnLastRow - j).Select
End If
Application.ScreenUpdating = True
LastLine:
End Sub
'删除所选区空列
Sub Delete_Empty_Columns()
Dim lnLastColumn As Long, i As Long, j As Long
Dim rnArea As Range
Application.ScreenUpdating = False
lnLastColumn = Selection.Columns.Count
Set rnArea = Selection
If rnArea.Columns.Count <= 1 Then
MsgBox ("请先选中一块多列包含文字的区域")
GoTo LastLine
End If
j = 0
For i = lnLastColumn To 1 Step -1
If Application.CountA(rnArea.Columns(i)) = 0 Then
rnArea.Columns(i).Delete
j = j + 1
End If
Next i
If (lnLastColumn - j) > 0 Then
rnArea.Resize(, lnLastColumn - j).Select
End If
Application.ScreenUpdating = False
LastLine:
End Sub |
|