+ Reply to Thread
Results 1 to 3 of 3

copying and pasting rows based on condition, VBA

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    copying and pasting rows based on condition, VBA

    Hi there,

    I have gone this far so far regarding using VBA to copy and paste rows into another worksheet based on condition. I have also attached the file for you to refer to. I'm really stuck here.

    So the idea here is....to copy and paste rows where column L's data contains "Yes" into another worksheet.

    Dim i As Long
    Dim j As Long
    Dim c As Long

    Dim ccm As Range
    Set ccm = Range("L3:L6000000")

    For c = 2 To 60000000
    If ccm.Cells(i, j).Value = "Yes" Then

    Rows(i, j).Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Paste
    c = c + 1
    Else
    MsgBox "No CCM encounters found"
    End If

    Next j
    Next i

    End Sub

    I keep getting the error message saying "invalid next reference".
    Attached Files Attached Files

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: copying and pasting rows based on condition, VBA

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: copying and pasting rows based on condition, VBA

    Lifeseeker;

    Your problem is obvious, but it's against the rules for anyone to respond to your question until you correct the infraction.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1