我有一张工作表,如果最后一列的值等于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
答案 0 :(得分:0)
有很多方法可以做到这一点,最简单的方法是保留一个行计数器,它跟踪你在另一张表上使用了多少行。每次增加此计数器一次。假设您在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
正如人们所评论的那样,有许多方法可以做到这一点,所以要好好了解Stack Overflow,其他一些方法可能对你有吸引力。