+ Reply to Thread
Results 1 to 3 of 3

Macro - Automatically copying rows to csv file.

  1. #1
    Registered User
    Join Date
    03-21-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro - Automatically copying rows to csv file.

    Hi all!

    I'm new to the forum, but used Excel years ago. I'm having a little trouble getting a macro sorted!

    I need to copy rows based on a text value (R, Y, G, B, N) in column F, and copy those rows to a separate CSV file.

    So far, I've managed to make this work as a trial:

    Please Login or Register  to view this content.
    As you can see, I'm only copying to the next sheet to prove that it works, but I've hit a wall and need a bit of help!

    1) How do you enter an 'OR' rule? At the mo, only rows with 'R' in column F are copied, but I need to copy all rows with 'R' Or 'G' Or 'B' in column F.

    2) How can I copy it to a separate CSV file?

    3) Is it possible to have more than 2 macros in a single workbook? I need one to copy 'R'/'G'/'B' rows, one to copy 'Y' rows, and a third to copy 'N' rows. At present, if I create a third macro, the first one disappears!

    Any help would be very very much appreciated indeed!! Thanks so much in advance! Michael
    Last edited by Leith Ross; 03-21-2012 at 01:08 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Macro - Automatically copying rows to csv file.

    Quote Originally Posted by InXpress View Post
    1) How do you enter an 'OR' rule? At the mo, only rows with 'R' in column F are copied, but I need to copy all rows with 'R' Or 'G' Or 'B' in column F.
    Something like this (just an example, you need to adapt it for your specific need):
    Please Login or Register  to view this content.
    Or using Instr allows you to generalise the routine for handling RGB, Y or N (pass the required search string as a subroutine argument), something like this:
    Please Login or Register  to view this content.
    2) How can I copy it to a separate CSV file?
    Here's a routine and example call which saves the specified sheet as a CSV file:
    Please Login or Register  to view this content.
    3) Is it possible to have more than 2 macros in a single workbook? I need one to copy 'R'/'G'/'B' rows, one to copy 'Y' rows, and a third to copy 'N' rows. At present, if I create a third macro, the first one disappears!
    Yes, by putting the macros (subroutines/functions) below each other in one module or in separate modules. But, as I said, you could have one general routine which handles all 3 cases, depending on a search text parameter.

  3. #3
    Registered User
    Join Date
    03-21-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro - Automatically copying rows to csv file.

    Magic! Thanks so much! Worked a treat....

+ 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