2016-07-06 63 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 

由于人评论有很多很多很多方法可以做到这一点,从而对堆栈溢出好好看看,别的东西可能吸引你。

相关问题