+ Reply to Thread
Results 1 to 6 of 6

Help in an iterative macro to copy/skip row based on cell value

  1. #1
    Registered User
    Join Date
    03-28-2012
    Location
    Location
    MS-Off Ver
    Excel 2010
    Posts
    12

    Help in an iterative macro to copy/skip row based on cell value

    Hi,

    I have a list of customer contacts that are both active and inactive (indicated by column A as "Y" for Inactive or "N" for Not Inactive) in Sheet1. I'm trying to find a way to have Excel do an iterative query on the value in column A such that if the cell value for A2 = N, it will copy the associated row of data into another worksheet, Sheet2. If A2 value = Y, then skip that row, and perform the query on the next row, A3 to see if the value is N or Y.

    Complications:
    - All my data in this worksheet are linked from different files in the same directory as they are dynamic and liable to change, so I don't want to move, re-organize, manually manipulate any columns
    - I'm working with +14000 rows of data, so something automated (formula? macro?) would be required

    I've used IF() to return data in my Sheet2, which does only filter the active customers, but then for all rows where the value in column A = "Y" only show up as blank rows. I need a block of data without any gaps between them. Is there any way to do this? Any help would be extremely appreciated! I'm not well versed in VBA, but would be willing to experiment and learn if I had some guidance!

    Thanks!

  2. #2
    Registered User
    Join Date
    03-30-2012
    Location
    Germany
    MS-Off Ver
    Excel 2003/2010
    Posts
    9

    Re: Help in an iterative macro to copy/skip row based on cell value

    If I understand you correct, the easiest solution would be to use MSQuery.

    (I have a German Client, so I'm kinda guessing what it's called in English)

    Go to Data->Other Sources->Microsoft Query

    Source -> Excel
    File -> YourFile.xls
    Sheets -> Sheet1->Content(column A-Z)
    Filter -> Here you set to check if the data in A = Y (or N)

    Select Sheet2 for the output, and voila, you'll have all your data filtered by column A

    *edit*
    always mess up row/column
    Last edited by Fraenk; 03-30-2012 at 09:05 AM.

  3. #3
    Registered User
    Join Date
    03-28-2012
    Location
    Location
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help in an iterative macro to copy/skip row based on cell value

    Hi,

    Thanks for your suggestion... I never knew about MSQuery or any of its functions! However, when I tried to follow your directions, I got the following error: "This data source contains no visible tables." I can't select any sheets or do any filtering.

    Any other suggestions?

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

    Re: Help in an iterative macro to copy/skip row based on cell value

    Try the Advanced Filter, specifying the 'Copy to another location' option. You will need to set up the criteria range somewhere on a sheet.

  5. #5
    Registered User
    Join Date
    03-30-2012
    Location
    Germany
    MS-Off Ver
    Excel 2003/2010
    Posts
    9

    Re: Help in an iterative macro to copy/skip row based on cell value

    Quote Originally Posted by rhiminee View Post
    "This data source contains no visible tables."
    I got the same error once. It happened to me, because the sourcefile was a protected worksheet, just unprotect it and it should work again.
    If all fails, copy the data into a new file and try again.

    Never used Chippy's suggestion, maybe that would be easier, you could also give that a try as well.

    *edit*
    Last edited by Fraenk; 04-01-2012 at 04:56 AM.

  6. #6
    Registered User
    Join Date
    03-28-2012
    Location
    Location
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help in an iterative macro to copy/skip row based on cell value

    The worksheet was never protected... but it still doesn't work. I'm trying to minimize copying data to another location because if I can get this working, I will want to have another separate excel file be driven off of data from this one. Are there any other possible suggestions that I can try?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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