2016-05-21 6 views
0

値がtrueの場合は最後の行全体を選択する必要がありますが、それは機能しません。助けて。後に値がtrueの場合は行全体を選択しません

Private Sub CommandButton4_Click() 
    Dim erow, lastrow, i As Long 
    lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row 
    For i = 2 To lastrow 
    If Cells(i, 1) = Date And Cells(i, 2) = "Sales" Then 
    Rows(lastrow).Select 
    Selection.Copy 
    End If 
    Next 
    End Sub 

答えて

0

私だけの小さな変化にあなたのコードを実行しました:

Private Sub CommandButton4_Click() 
    Dim erow As Long, lastrow As Long, i As Long 

    lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row 

    For i = 2 To lastrow 
     If Cells(i, 1) = Date And Cells(i, 2) = "Sales" Then 
      Rows(lastrow).Select 
      Selection.Copy 
     End If 
    Next 
End Sub 

、それが働きました!

ご覧のとおり、それは行#7にを発見し、最後の行(#21行)コピー:

enter image description here

関連する問題