+ Reply to Thread
Results 1 to 3 of 3

Help with changing code

  1. #1
    Greg B
    Guest

    Help with changing code

    Hi all,

    I have this code (shown below) which looks up a value in column e and copies
    to another worksheet. I have it to copy the whole row, so how can I change
    it to only copy columns a & e on row 5 for example.


    Dim rng As Range, cell As Range, col As Long
    Dim rw As Long
    col = 5
    rw = 1
    With Worksheets("list")
    Set rng = .Range(.Cells(1, col), .Cells(Rows.Count, col).End(xlUp))
    End With
    For Each cell In rng
    If LCase(cell.Value) = "yes" Then
    cell.EntireRow.Copy Destination:=Worksheets("fortnight") _
    .Cells(rw, 1)
    rw = rw + 1
    End If
    Next

    Thanks in advance

    Greg



  2. #2
    Dave Peterson
    Guest

    Re: Help with changing code

    Copy both cells individually:

    Dim rng As Range, cell As Range, col As Long
    Dim rw As Long
    col = 5
    rw = 1
    With Worksheets("list")
    Set rng = .Range(.Cells(1, col), .Cells(Rows.Count, col).End(xlUp))
    End With
    For Each cell In rng
    If LCase(cell.Value) = "yes" Then
    cell.copy _
    destination:=worksheets("fortnight").cells(rw,1)
    'copy column E to column B (=2)?????
    cell.offset(0,4).copy _
    destination:=worksheets("fortnight)".cells(rw,2)
    rw = rw + 1
    End If
    Next

    Greg B wrote:
    >
    > Hi all,
    >
    > I have this code (shown below) which looks up a value in column e and copies
    > to another worksheet. I have it to copy the whole row, so how can I change
    > it to only copy columns a & e on row 5 for example.
    >
    > Dim rng As Range, cell As Range, col As Long
    > Dim rw As Long
    > col = 5
    > rw = 1
    > With Worksheets("list")
    > Set rng = .Range(.Cells(1, col), .Cells(Rows.Count, col).End(xlUp))
    > End With
    > For Each cell In rng
    > If LCase(cell.Value) = "yes" Then
    > cell.EntireRow.Copy Destination:=Worksheets("fortnight") _
    > .Cells(rw, 1)
    > rw = rw + 1
    > End If
    > Next
    >
    > Thanks in advance
    >
    > Greg


    --

    Dave Peterson

  3. #3
    Greg B
    Guest

    Re: Help with changing code

    Thank you just what I wanted

    Greg



+ 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