Results 1 to 10 of 10

VBA Copy Code is copying more than the cells needed

Threaded View

dgilbrea VBA Copy Code is copying more... 07-08-2010, 12:09 AM
shg Re: VBA Code 07-08-2010, 12:21 AM
royUK Re: VBA Code 07-08-2010, 01:09 AM
foxguy Re: VBA Copy Code is copying... 07-11-2010, 10:11 PM
dgilbrea Re: VBA Copy Code is copying... 07-12-2010, 05:25 PM
foxguy Re: VBA Copy Code is copying... 07-12-2010, 08:40 PM
dgilbrea Re: VBA Copy Code is copying... 07-14-2010, 09:20 AM
foxguy Re: VBA Copy Code is copying... 07-14-2010, 02:36 PM
foxguy Re: VBA Copy Code is copying... 07-14-2010, 02:43 PM
dgilbrea Re: VBA Copy Code is copying... 07-19-2010, 11:59 AM
  1. #1
    Registered User
    Join Date
    07-06-2010
    Location
    McAlester, OK
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA Copy Code is copying more than the cells needed

    I have a workbook with two main worksheets (Sheet1 and Sheet2). Sheet1 has numerous rows and each row contains information relating to a student. The student name is the first cell in the row. Each row contains a dropdown list (Yes or No) on one of the fields. I am trying to create a code that is activated when the Yes in the row is selected and it will copy the student name from the first cell to Sheet2 in the next available cell that is empty in column A. I currently have a code that is almost working like I need, however when it copies it copies all of the students names that have Yes selected rather than just the row that is active. The code follows. Any help would be greatly appreciated.
    Public Sub CopyRows()
        Sheets("Sheet1").Select
        ' Find the last row of data
        FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
        ' Loop through each row
        For x = 4 To FinalRow
            ' Decide if to copy based on column H
            ThisValue = Cells(x, 8).Value
            If ThisValue = "YES" Then
                Cells(x, 1).Copy
                Sheets("Sheet2").Select
                NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
                Cells(NextRow, 1).Select
                ActiveSheet.Paste
                Sheets("Sheet1").Select
    
            End If
        Next x
    End Sub
    Last edited by dgilbrea; 07-19-2010 at 12:01 PM. Reason: To conform to Rules

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