2017-06-18 14 views
0

我想刪除我的工作表中的emptry行。最初有一行中的數據,然後一個宏將切斷這些數據並移動到Sheet2,並留下一個空行。 我希望那一行被刪除,或者如果下面有任何行數據,我希望它們向上移動。刪除Excel vba中的空行後,該行的整個數據被複制到另一個頁面

screenshot

Private Sub cmdMove_Click() 

Dim myLog As Worksheet 
    Dim myLogSheet As Range 

    Dim i As Long 
    i = 1 

    i = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row + 1 

    Set myLog = Sheets("Sheet1") 
    Set myLogSheet = myLog.Range("B:B").Find(txtID.Value, , , xlWhole) 

    If Not myLogSheet Is Nothing Then 
     myLogSheet.Offset(0, 2) = Format(Now, "hh:mm:ss") 

     Application.Wait Now + TimeValue("00:00:02") 'Delay to see the punch out time... 
     DoEvents 

     myLogSheet.EntireRow.Cut Sheet2.Cells(i, "A") 

     ' After cutting the entire row, I want the below data to move up to avoid any empty 
     'row.. thank you. 
     On Error Resume Next 

    Else 
     txtName.Value = "NO RECORD" 
    End If 

End Sub 

回答

0

更換,如果用下面的語句的一部分,它會工作。

If Not myLogSheet Is Nothing Then 
    Dim foundRow as long 
    myLogSheet.Offset(0, 2) = Format(Now, "hh:mm:ss") 
    foundRow = myLogSheet.row 

    Application.Wait Now + TimeValue("00:00:02") 'Delay to see the punch out time... 
    DoEvents 

    myLogSheet.EntireRow.Cut Sheet2.Cells(i, "A") 

    ' After cutting the entire row, I want the below data to move up to avoid any empty 
    'row.. thank you. 
    myLog.Rows(foundRow).select 
    Selection.Delete Shift:=xlUp 
    On Error Resume Next 

Else 
    txtName.Value = "NO RECORD" 
End If 
+0

檢查上面的回答修改,它應該工作。 – Karpak

0

在最後一行添加以下代碼

列(1).SpecialCells(xlCellTypeBlanks).entirerow.Delete

相關問題