+ Reply to Thread
Results 1 to 15 of 15

Find a value, copy the row, move to next row.

Hybrid View

OSUBigToe Find a value, copy the row,... 04-10-2013, 09:30 AM
AB33 Re: Find a value, copy the... 04-10-2013, 09:39 AM
OSUBigToe Re: Find a value, copy the... 04-10-2013, 09:55 AM
AB33 Re: Find a value, copy the... 04-10-2013, 09:59 AM
OSUBigToe Re: Find a value, copy the... 04-10-2013, 10:06 AM
AB33 Re: Find a value, copy the... 04-10-2013, 10:33 AM
AB33 Re: Find a value, copy the... 04-10-2013, 10:26 AM
AB33 Re: Find a value, copy the... 04-10-2013, 10:46 AM
OSUBigToe Re: Find a value, copy the... 04-10-2013, 10:50 AM
AB33 Re: Find a value, copy the... 04-10-2013, 10:57 AM
OSUBigToe Re: Find a value, copy the... 04-10-2013, 11:05 AM
AB33 Re: Find a value, copy the... 04-10-2013, 11:17 AM
AB33 Re: Find a value, copy the... 04-10-2013, 11:20 AM
AB33 Re: Find a value, copy the... 04-10-2013, 11:36 AM
OSUBigToe Re: Find a value, copy the... 04-10-2013, 11:40 AM
  1. #1
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Find a value, copy the row, move to next row.

    I need to search for a value in column "J" in "sheet1" then copy the data that is in that row from Column a to k into sheet2. Currently I have the following that copies the whole row:
     Sub copyrows()
         
        Dim tfCol As Range, Cell As Object
         
        Set tfCol = Range("j2:j3200")
         
        For Each Cell In tfCol
             
            If IsEmpty(Cell) Then
                Exit Sub
            End If
             
            If Cell.Value = "Startup" Then
                Cell.EntireRow.Copy
                Sheets("Startup").Select
                ActiveSheet.Range("A3200").End(xlUp).Select
                Selection.Offset(1, 0).Select
                ActiveSheet.Paste
            End If
             
        Next
         
    End Sub
    I need to only copy and paste Column "a" through "k" and to move to the next row down after it fills the value. Help?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

     Sub copyrows()
         
        Dim tfCol As Range, Cell As Object
         
        Set tfCol = Range("j2:j3200")
         
        For Each Cell In tfCol
             
            If IsEmpty(Cell) Then
                Exit Sub
            End If
             
            If Cell.Value = "Startup" Then
                Cell.Offset(, -9).Resize(, 11).Copy
                Sheets("Startup").Select
                ActiveSheet.Range("A3200").End(xlUp).Select
                Selection.Offset(1, 0).Select
                ActiveSheet.Paste
            End If
             
        Next
         
    End Sub

  3. #3
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Find a value, copy the row, move to next row.

    Thanks AB33 that defiantly helps (and works)...any idea how to get it to paste each result to a new row? For example when you run this macro row 2 is copied, then row 7 on top of it, then row 10 on top and so on. I want the macro to start at the top and do this:
    Find first row in column J that is "startup->copy to the other sheet->find the next value in J->copy it to the next blank row and so on


    Quote Originally Posted by AB33 View Post
     Sub copyrows()
         
        Dim tfCol As Range, Cell As Object
         
        Set tfCol = Range("j2:j3200")
         
        For Each Cell In tfCol
             
            If IsEmpty(Cell) Then
                Exit Sub
            End If
             
            If Cell.Value = "Startup" Then
                Cell.Offset(, -9).Resize(, 11).Copy
                Sheets("Startup").Select
                ActiveSheet.Range("A3200").End(xlUp).Select
                Selection.Offset(1, 0).Select
                ActiveSheet.Paste
            End If
             
        Next
         
    End Sub

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    Sub copyrows()
         
        Dim tfCol As Range, Cell As Object
         
        Set tfCol = Range("j2:j" & Cells(Rows.Count, "J").End(xlUp).Row)
         
        For Each Cell In tfCol
             
            If IsEmpty(Cell) Then
                Exit Sub
            End If
             
            If Cell.Value = "Startup" Then
                Cell.Offset(, -9).Resize(, 11).Copy
                Sheets("Startup").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
               
            End If
             
        Next
         
    End Sub

  5. #5
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Find a value, copy the row, move to next row.

    It jumps back and forth between sheets but is only overwritting the data into a2:k2


    Quote Originally Posted by AB33 View Post
    Sub copyrows()
         
        Dim tfCol As Range, Cell As Object
         
        Set tfCol = Range("j2:j" & Cells(Rows.Count, "J").End(xlUp).Row)
         
        For Each Cell In tfCol
             
            If IsEmpty(Cell) Then
                Exit Sub
            End If
             
            If Cell.Value = "Startup" Then
                Cell.Offset(, -9).Resize(, 11).Copy
                Sheets("Startup").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
               
            End If
             
        Next
         
    End Sub

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    This is better code

    Sub test()
    Dim i&, LR&
    With ActiveSheet
      LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
      For i = 2 To LR
       If Len(.Cells(i, 10)) Then
            If Trim(.Cells(i, 10)) = "Startup" Then
            .Cells(i, 1).Resize(, 11).Copy
             Sheets("Startup").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
            End If
         End If
      Next i
     End With
    End Sub

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    No, it should not be.
    You should be on the active and have a sheet called Startup and run the code.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    Please do not reply with quote

    I think there is a flaw in your code

      If IsEmpty(Cell) Then
                Exit Sub
    As soon as the code finds blank cell in column,J, it is terminated, so It will not go in to next cell as you might have expected

  9. #9
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Find a value, copy the row, move to next row.

    Sorry about that. Tried the new code and it is doing the same thing i.e. not putting each instance of "startup" in a new row on the new sheet

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    "startup" in a new row on the new sheet .
    Do you want to create a new sheet for each startup"? Please post your sample book

  11. #11
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Find a value, copy the row, move to next row.

    I had to remove data from Column a,b,c as it is confidential
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    Okay!
    If you are copying to column A and that column first row is blank, the code will keep overwriting all the subsequent cells in to it because VBA treats the next empty cell which is column A.
    The easiest way would be to include the same heading on the start sheet in row 1, so that the next empty row would be 2 and so on.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    Or if you wan to copy staring in column B as your data format shows, you can use line


    Sheets("Startup").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find a value, copy the row, move to next row.

    Lately, I am learning on overcoming my phobia with filter and a have a loop fatigue

    Sub Converted()
        Dim LR&
        Application.ScreenUpdating = False
        With Sheets("Main")
            LR = .Range("J" & Rows.Count).End(xlUp).Row
            .Range("A1:K" & LR).AutoFilter 10, "Startup"
            .Range("A1:K" & LR).Copy
            Sheets("Startup").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
            Application.CutCopyMode = True
            .AutoFilterMode = False
        End With
        Application.ScreenUpdating = True
    End Sub

  15. #15
    Registered User
    Join Date
    11-22-2012
    Location
    Canton, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Find a value, copy the row, move to next row.

    Yep "A" was blank in some. Fixed the problem. Last code is super fast too. THanks

+ 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