+ Reply to Thread
Results 1 to 9 of 9

Save row to array

  1. #1
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Save row to array

    Tough nut to crack for me. I'm writing a small marcro that loops through every row on a sheet. If the row meets a certain condition, (part of it) should be transferred to another sheet.

    The way I do it is now is no good. Every time I need to copy a row from the source sheet, I copy it, swap to the target sheet and paste it there. Then I swap back to the source sheet, ...
    It's a spectacular show but it doesn't look too efficient

    So I was thinking of making a one dimensional array and populate it with rows (colums A-F). I can get a cell in an array but how do I get part of a row in it? Every time I think something is impossible I'm mistaken so I'm hoping this is one of those times

    Cheers,
    Jeroen
    Last edited by Jeroen1000; 08-16-2010 at 07:58 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Save row to array

    The fastest way would probably be to use a filter and then just copy the visible rows in one go. We'd need to know more detail to write the code though.
    If you really want to loop, you can use an array of arrays and then write that to the worksheet at the end.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Save row to array

    I'll start looking into filters. Sounds like good way of doing things. I simplified the criteria to 1 for illustrating purposes:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Save row to array

    Filters won't work with colours in 2003, so you'll need a loop after all.
    Try this:
    Please Login or Register  to view this content.
    Last edited by romperstomper; 08-12-2010 at 08:31 AM. Reason: add code.

  5. #5
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Save row to array

    So it would be possible to build it in 2007? That would be good news as I've got them both

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Save row to array

    Probably - I've just posted some code that should work in either.

  7. #7
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Save row to array

    Romper that worked great. Just heading back to thank you. I think I understand how this array thing works.

    There is one funny thing though. No matter how I format the date, it keeps switching the month and day. So 10/06/2010 (the 10th of Juli) becomes the 6th of October.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Save row to array

    Try replacing all instances of .Value with .Value2
    You will need to format the destination cells as dates though.

  9. #9
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Save row to array

    Applying this to a cell should work too (credits go to you though as I found it in a search). CDate(txtDate.Value). However, that would probably require me to loop through the array and apply this to every date.

    So I'm going to try your suggestion first

    edit: Yep, value2 seems to copy date and currency without the formatting. It's either reformatting the specific array index which holds the date/currency to the correct local (if you use value) or formatting the destinations cells to date (if you use value2).

    Just 4 fun

    Please Login or Register  to view this content.
    Last edited by Jeroen1000; 08-16-2010 at 03:37 AM.

+ 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