+ Reply to Thread
Results 1 to 8 of 8

select, copy, and paste multiple different rows to new sheet

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    15

    select, copy, and paste multiple different rows to new sheet

    I need to select all rows that have an "x" in column B. Then I need to paste those rows to a new sheet. I don't know much about VBA, so this is as far as I could get.

    Sub Macro4()

    'Define last row
    Dim lastrow As Integer
    lastrow = Range("C" & Rows.Count).End(xlUp).Row


    'Run loop
    For i = 1 To lastrow

    If Sheets("Sheet1").Cells(i, 2).Value = "x" Then
    Sheets("Sheet1").Cells(i, 2).EntireRow.Copy
    Sheets("Sheet2").Select
    Range("A1").Select
    ActiveSheet.Paste
    End If

    Next i

    End Sub


    I also tried this:

    Sub Macro5()
    Dim text As String
    text = "x"

    For Each cell In Sheets("Sheet1").Columns("B:B")
    If ActiveCell = text Then
    EntireRow.Copy
    Sheets("Sheet2").Range("A1").Select
    Selection.Paste
    End If
    Next cell

    End Sub

  2. #2
    Registered User
    Join Date
    10-30-2012
    Location
    Modlin , Poland
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    42

    Re: select, copy, and paste multiple different rows to new sheet

    not sure you really want this, but try :

    Please Login or Register  to view this content.

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

    Re: select, copy, and paste multiple different rows to new sheet

    Please use code tags with your code as per forum's rule.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: select, copy, and paste multiple different rows to new sheet

    Hi prjames3,

    Use this code, it may help you

    Sub CopyNonBlanks()
    Dim EndRow As Integer
    Application.ScreenUpdating = False
    With Sheet3
    .AutoFilterMode = False
    EndRow = .Range("H" & Rows.Count).End(xlUp).Row
    .Range("H1:H" & EndRow ).AutoFilter Field:=1, Criteria1:="<>"
    .Range("H1:H" & EndRow ).Copy Destination:=Sheet2.Range("A1")
    .Range("H1").AutoFilter
    End With
    Application.ScreenUpdating = True
    End Sub

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

    Re: select, copy, and paste multiple different rows to new sheet

    Ankit,
    You are also not using code tags. Please take a moment to read forum's rule.

  6. #6
    Registered User
    Join Date
    07-10-2013
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select, copy, and paste multiple different rows to new sheet

    Thanks for the help. I'll remember to use code tags next time. AB33, when I run your code it looks like all the rows are being copied, but the result on sheet 2 is only the last row with an "x" in column b from sheet 1 pasted in row 2.

  7. #7
    Registered User
    Join Date
    07-10-2013
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select, copy, and paste multiple different rows to new sheet

    Actually I just fixed it. Here's the code:

    Please Login or Register  to view this content.

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

    Re: select, copy, and paste multiple different rows to new sheet

    prjames3,
    They are not my code, I only adjusted your codes. You have two codes and both should work, unless the "x" is upper case.

    This is my code.

    Please Login or Register  to view this content.

+ 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