Consulting

Results 1 to 8 of 8

Thread: Copy values from one sheet to another

  1. #1
    Banned VBAX Regular
    Joined
    Mar 2007
    Posts
    13
    Location

    Copy values from one sheet to another

    Hi ,
    I am trying to copy values from one sheet to another on the bases of a particular column.
    For eg : I have a worksheet with three sheets A,B and C... i want to copy the rows of Sheet A to Sheet B if the value of the columns = PL . If the value is anything other than PL then the row value should be copied to Sheet C.
    I am attching the sample file which should be the result.
    Pls help
    Last edited by Sreeja; 04-16-2007 at 05:32 AM. Reason: File added

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    So something like:
    [vba]
    If Sheets("Sheet A").Range("A1").Value = "PL" Then
    Range("A1").EntireRow.Copy Destination:=Sheets("Sheet B").Range("A1")
    Else
    Range("A1").EntireRow.Copy Destination:=Sheets("Sheet C").Range("A1")
    End If

    [/vba]

    The you just replace "A1" with a variable row like ("A" & i) within your loop.

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I am trying to make this work for me with no luck. I have a similar situation I need it to look at column "O" so if "O" has the value "1" then copy entire row and paste in sheet 2

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Post your workbook please
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    This is the sheet. I would like to transfer the entire row of the one's that have a "1" in Column "O".

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Try this:

    [VBA]Sub TransferIssues()
    Dim wksSource As Worksheet, wksDest As Worksheet
    Dim rngTarget As Range
    Dim lngRow As Long, lngRowCount As Long
    Set wksSource = Sheet1
    Set wksDest = Sheet2
    With wksSource
    lngRowCount = .Cells(.Rows.Count, "O").End(xlUp).Row
    End With
    With wksDest
    Set rngTarget = .Cells(.Cells(.Rows.Count, 15).End(xlUp).Row + 1, 1)
    End With
    For lngRow = 2 To lngRowCount
    With wksSource.Cells(lngRow, "O")
    If .Value = 1 Then
    .EntireRow.Copy rngTarget
    Set rngTarget = rngTarget.Offset(1, 0)
    End If
    End With
    Next lngRow
    End Sub
    [/VBA]

    HTH
    Rory

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Em,
    This should get you started. You will probably want to run a sort after the copy if you copy a lot of data....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Now you have some options......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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