2017-08-04 69 views
-1

在我的Excel表格中,我希望將整行從Sheet1(「Action Register」)移動到Sheet2(「Completed」)if單詞「closed」位於J列的行中,然後刪除第一張表中的行。 這是我到目前爲止的代碼,但它並沒有將「Action Register」中的所有「已關閉」行復制到「已完成」工作表,它只複製其中一行,然後所有行都被刪除。有人能幫我指出我出錯的地方嗎? 謝謝如何根據單元格值將一行移動到另一列,然後刪除該行

Sub Copyx() 

    Sheets("Action Register").Select 

    RowCount = Cells(Cells.Rows.Count, "I").End(xlUp).Row 

    For i = 1 To RowCount 

     Range("J" & i).Select 

     check_value = ActiveCell 

     If check_value = "closed" Or check_value = "closed" Then 

      ActiveCell.EntireRow.Copy 

      Sheets("Completed").Select 

      RowCount = Cells(Cells.Rows.Count, "A").End(xlUp).Row 

      Range("A" & RowCount + 1).Select 

      ActiveSheet.Paste 

      Sheets("Action Register").Select 

     End If 
    Next 


'- 

    Dim c As Range 

    Dim SrchRng 

    Set SrchRng = ActiveSheet.Range("J1", ActiveSheet.Range("J50000").End(xlUp)) 

    Do 

     Set c = SrchRng.Find("closed", LookIn:=xlValues) 

     If Not c Is Nothing Then c.EntireRow.Delete 

    Loop While Not c Is Nothing 

End Sub 
+0

移動一行到另一個工作表,但它在J列找單詞「封閉式」觸發我曾嘗試與移動 – Jarvis595

+0

,並沒有能夠得到一個能正常工作,這是最近我得到了(與上面的代碼),除了它只是複製其中一個條目,而不是所有的事實。 – Jarvis595

回答

0

試試這個切割和插入來實現這一點。

Sub Copyx() 

Sheets("Action Register").Select 

RowCount = Cells(Cells.Rows.Count, "I").End(xlUp).Row 

For i = 1 To RowCount 

Range("J" & i).Select 

check_value = ActiveCell 

If check_value = "closed" Or check_value = "closed" Then 

ActiveCell.EntireRow.Cut 

Sheets("Completed").Select 

RowCount = Cells(Cells.Rows.Count, "A").End(xlUp).Row 

Range("A" & RowCount + 1).Select 
Selection.Insert Shift:=xlDown 

Sheets("Action Register").Select 

End If 
Next 
'- 

Dim c As Range 

Dim SrchRng 

Set SrchRng = ActiveSheet.Range("J1", ActiveSheet.Range("J50000").End(xlUp)) 

Do 

Set c = SrchRng.Find("closed", LookIn:=xlValues) 

If Not c Is Nothing Then c.EntireRow.Delete 

Loop While Not c Is Nothing 

End Sub 
相關問題