Consulting

Results 1 to 2 of 2

Thread: Copying with condition

  1. #1

    Question Copying with condition

    I want to copy the rows that contain the word "Other" in column A from sheet D and paste them into sheet SORT - it is not giving an error and not doing anything. What am I doing wrong?

    Sub Command()
    
    
    a = Worksheets("D").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To a
        If Worksheets("D").Cells(i, 1).Value = "Other" Then
        
        Worksheets("D").Rows(i).Copy
        Worksheets("SORT").Rows(i).Activate
        b = Worksheets("SORT").Cells(Rows.Count, 1).End(xlUp).Row
        Worksheets("SORT").Cells(b + 1, 1).Select
        ActiveSheet.Paste
        Worksheets("D").Activate
        
        End If
    Next
    
    Application.CutCopyMode = False
    ThisWorkbook.Worksheets("D").Cells(1, 1).Select
    
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    try:
    Sub Command()
    With Worksheets("D")
      For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
        If .Cells(i, 1).Value = "Other" Then .Rows(i).Copy Worksheets("SORT").Cells(Rows.Count, 1).End(xlUp).Offset(1)
      Next
      Application.Goto .Cells(1, 1)
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •