>即時新聞-熱門

2007年11月9日星期五

EXCEL - 刪除空白列

Sub 刪除空白列()
Dim myRng As Range
Dim myRng2 As Range
Dim mySht As Worksheet
Dim x, x1, i, j, n
Set mySht = Worksheets(1) '任意的工作表
Set myRng = mySht.UsedRange
Range(myRng.Address).Select
Set myRng = ActiveCell
x = ActiveCell.Row
Set myRng2 = myRng.SpecialCells(xlCellTypeLastCell)
Range(myRng2.Address).Select
x1 = ActiveCell.Row
Range(myRng.Address).Select
Set myRng = ActiveCell
ActiveCell.Select

For i = 0 To (x1 - x)

If ActiveCell.Value = Empty Then
Selection.Delete Shift:=xlUp
ActiveCell.Offset(0, 0).Select
Else
ActiveCell.Offset(1, 0).Select
End If

Next i


Set myRng = Nothing
Set myRng2 = Nothing '物件的釋放
Set mySht = Nothing
End Sub

 
妹咕數位學園歡迎網友們來信指教 妹咕信箱