2017-06-18 1 views
0

シート内の空行を削除しようとしています。当初、その行にデータがあり、マクロはそのデータを切り取り、Sheet2に移動して空の行を残します。 その行を削除したい、または下に行データがある場合は、その行を上に移動します。Excel vbaの空の行を、その行のデータ全体が別のsheetにコピーされた後に削除します。

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

関連する問題