Results 1 to 3 of 3

Thread: Excel - Copy select rows

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    10

    Excel - Copy select rows

    Is there a way to select rows based on the criteria in a cell? For ex:
    suppose you have a spreadsheet like the following

    5 342
    6 347
    5 654
    6 743
    5 634
    6 874
    6 234
    6 654

    I want to select all of the rows with a 5 preceeding it. I'm trying to automate this using another program (LabVIEW). So I'm actually using ActiveX controls, but I can also use a macro if needed. I'll be slecting the rows and pasting them into a newly created worksheet.

    Thanks.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Excel - Copy select rows

    Select the range into a range object.
    Sort the range on the first column/char.
    Use code or a find to get the top and bottomw rows.
    Change the range to the top and bottom and copy.
    Paste into the new sheet.

    Should be possible. Perhaps a sort is all you need?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Re: Excel - Copy select rows

    I agree with ECNIV but here's VBA in case you want it .... I hope this is right because this is the first time I've posted VBA (just a beginner)

    Name a range on your spreadsheet.....we'll say "data" in cell A1 and your numbers start in A2. For sheet2 name a range we'll call "data2"

    y=1
    x=1
    Do until range("data").offset(x,0) = ""
    Do
    If trim(left(range("data").offset(x,0)),1) = "5" then
    Range("data").Offset(x, 0).EntireRow.Select
    Sheets("sheet2").Select
    Range("data2").Offset(y, 0).EntireRow.Select
    ActiveSheet.Paste
    Sheets("sheet1").Select
    exit do
    end if
    x=x+1
    Loop until trim(left(range("data").offset(x,0)),1) = "5"

    y=y+1

    Loop
    end sub

Posting Permissions

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



Click Here to Expand Forum to Full Width