2016-07-06 61 views
-1

我有一個工作表,如果最後一列的值等於false,則需要移動該行。 我不知道如何移動到工作表2並製作完整的工作表。 感謝您的幫助。將行移到另一個工作表

Sub DeleteMatches2() 
    Dim a As Range, b As Range 
    Dim c As String 
    'The column that has the value is V2 
    With Sheets("Controle Estoque Fixo") 
     Set a = .Range(.Cells(2, "V"), .Cells(Rows.Count, "V").End(xlUp)) 
    End With 

    For Each b In a 
     If b.Value = "False" Then 
      Sheets("Sheet1").Select 
      'know I am lost 

     End If 
    Next 
End Sub 
+4

你找到了嗎?在這裏有一個如何做到這一點的bagazillion例子。另外,你有什麼*實際嘗試*將行復制到另一個表單? –

+0

快速注意,當你設置一個''時,還要確保在'Rows.Count'之前加'.'。對於下一部分,您只需要在Sheet2中找到下一行(使用變量),然後就可以剪切/粘貼。有很多你在這裏要求的例子,所以只需使用搜索框。我建議使用宏記錄器,剪切/粘貼,並看看代碼是什麼樣的,並從那裏調整。 – BruceWayne

+1

大聲笑我喜歡你如何使用'與'然後繼續使用'選擇'XD – findwindow

回答

0

有很多方法可以做到這一點,最簡單的就是保持一個行計數器,它跟蹤你多少行使用上另一片。每次將此計數器加1。讓我們假設你有工作表Sheet1上列標題,所以第一個可用行是2行:

Sub DeleteMatches2() 

    Dim a As Range, b As Range 
    Dim c As String 
    Dim rowCounter As Long 

    rowCounter = 2 ' start at row 2 

    'The column that has the value is V2 
    With Sheets("Controle Estoque Fixo") 
     Set a = .Range(.Cells(2, "V"), .Cells(Rows.Count, "V").End(xlUp)) 
    End With 

    For Each b In a 
     If b.Value = "False" Then 
      'Sheets("Sheet1").Select ' you don't need to select an object to access it, so remove this 
      'here's the bit you need 
      Sheets("Controle Estoque Fixo").Rows(b.row).Cut Sheets("Sheet1").Rows(rowCounter) ' this cuts and pastes all in one line 
      ' you use the row counter to specify the destination 

      rowCounter = rowCounter + 1 ' the next time you'll paste on the next row 

     End If 
    Next 
End Sub 

由於人評論有很多很多很多方法可以做到這一點,從而對堆棧溢出好好看看,別的東西可能吸引你。

相關問題