+ Reply to Thread
Results 1 to 3 of 3

Conditionally Copying Rows

  1. #1
    Registered User
    Join Date
    05-20-2011
    Location
    Connecticut
    MS-Off Ver
    Excel 2007
    Posts
    5

    Conditionally Copying Rows

    My ultimate goal is to be able to have someone who has no knowledge of Excel function or macros to be able to go to a sheet, turn on and off certain rows in a second sheet, and have those rows appear in a third sheet.

    An example would be:

    Sheet1
    a Y
    b Y
    c N
    d N
    e Y

    Sheet2
    a asdf 2309 a
    b asdq 3092 bn
    c faon 2-392 klna
    d ofan 9801 lkn
    e fando 1091 lkn

    Sheet3 after macro
    a asdf 2309 a
    b asdq 3092 bn
    e fando 1091 lkn

    What I am currently doing is clearing Sheet3 and then looping through Sheet1 until empty, copying sheet2 row to sheet3 row as it finds a "Y":

    Set i = Sheets("Sheet1")
    Set w = Sheets("Sheet2")
    Set s = Sheets("Sheet3")
    Dim d
    Dim j
    d = 1
    j = 2

    Sheets("Sheet3").Cells.Clear

    Do Until IsEmpty(i.Range("B" & j))
    If i.Range("B" & j) = "Y" Then
    d = d + 1
    s.Rows(d).Value = w.Rows(j).Value
    Else
    End If
    j = j + 1
    Loop


    It does crop the correct amount of rows switched off from Sheet1, but it seems to have issues following after that. I currently have a list of about 15, and have tried debugging by trying all sorts of combinations of 'ons and offs'. I can find no pattern at all, and can't find anything wrong with the macro.

    Along with this, it does not want to hold the format of the text being 'copied.' Some cells are formatted as straight text, both on Sheet2 and in Sheet3, and still seem to become 'General' before moving. Cells containing data like "10,3892,289,12,2000" are lost.

    I apologize if this is not allowed, but I'd rather not create multiple posts if I can. A second macro is currently working to save out Sheet3 as a CSV file. It works great, but testing on a Mac results in nothing; it seems to have to do with the way they save to CSV, specifically as a "Windows CSV." The macro right now contains the format as xlCSV, and I am not sure how to make this compatible across operating systems.

    Thanks in advance, and again my apologies if I haven't followed proper forum procedure.

  2. #2
    Registered User
    Join Date
    05-20-2011
    Location
    Connecticut
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Conditionally Copying Rows

    I was able to find a solution to the CSV issue I mentioned: found this helpful chart through many many searches: Microsoft Excel XFileFormats. The filetype I was looking for was "xlCSVWindows" which will work on both Windows and Mac OS's.

    Still looking for a solution to the main issue though, thanks again.

  3. #3
    Registered User
    Join Date
    05-20-2011
    Location
    Connecticut
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Conditionally Copying Rows

    I hate to do this, but bumping for a response; I've been trying to work this out for a while, and it's the only thing holding me from fully automating this process!

    Thanks again.

+ 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