Sub 删除空行() Dim arr, arr1, arr2 On Error GoTo ren Set d1 = CreateObject("Scripting.Dictionary") a = InputBox("使用说明:" & Chr(13) & "一、删除当前表整行为空只需输入数字,如:1或2或3...." & Chr(13) & "二、可同时对多工作表进行删除操作,只需在!号前面加上通配附或字附串,如*!1 或 *月*!1 或 *月!2" & Chr(13) & "三、支持单列或多列为空删除,如:2列和3列为空则删除行 1,2:3 或 *!1,2:3", "删除空行") If a = "" Then Exit Sub Application.ScreenUpdating = False If a Like "*!*" Then arr = Split(a, "!") arr1 = Split(arr(1), ",") If UBound(arr1) = 0 Then For i = 1 To 256 s = d1(i & "a") Next i Else arr2 = Split(arr1(1), ":") For i = 0 To UBound(arr2) s = d1(arr2(i) & "a") Next i End If For Each sh In Sheets If sh.Name Like arr(0) Then sh.Select Call sckh(arr1(0), d1) End If Next sh Else arr = Split(a, ",") If UBound(arr) = 1 Then arr1 = Split(arr(1), ":") For i = 0 To UBound(arr1) s = d1(arr1(i) & "a") Next i Else For i = 1 To 256 s = d1(i & "a") Next i End If Call sckh(arr(0), d1) End If Application.ScreenUpdating = True Exit Sub ren: End Sub Sub sckh(x, d1) Dim i As Long Dim j As Long Dim lng As Long Dim lng2 As Long On Error GoTo ren If x < 0 Then x = 1 lng = ActiveSheet.UsedRange.Rows.Count lng2 = ActiveSheet.UsedRange.Columns.Count ReDim arr(1 To lng, 1 To 1) rng = Cells(x, 1).Resize(lng, lng2) For i = 1 To lng For j = 1 To lng2 If rng(i, j) <> "" And d1.Exists(j & "a") Then arr(i, 1) = i Exit For End If Next Next Cells(x, lng2 + 1).Resize(lng, 1) = arr Cells(x, 1).Resize(lng, lng2 + 1).Sort Key1:=Cells(x, lng2 + 1), Order1:=xlAscending z = Cells(65536, lng2 + 1).End(xlUp).Row + 1 Rows(z & ":65536").Delete Cells(x, lng2 + 1).Resize(lng, 1) = "" ren: End Sub
[此贴子已经被作者于2008-6-24 22:20:41编辑过] |