+ Reply to Thread
Results 1 to 20 of 20

Generate array from multiple rows

  1. #1
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Generate array from multiple rows

    Hi,

    I have a large file with ~800K rows and I'm trying to generate an array from Column C from the names in Column B or ID in Column A (grouping Column A or B into 1 row and creating an array from Column C in the same row).

    Please see attached sample data and output as I'm having a hard time explaining.

    Thanks for your help!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    See if this works
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    Hi !

    According to your attachment try this demonstration !

    PHP Code: 
    Sub Demo1()
              
    Dim VR&, L&
        
    With Worksheets("data").UsedRange.Rows
            ReDim V
    (1 To .Count 11 To 3)
            For 
    2 To .Count
                
    If .Cells(R1).Value = .Cells(11).Value Then
                              V
    (L3) = V(L3) & "," & .Cells(R3).Value
                
    Else
                    If 
    L Then V(L3) = V(L3) & "}"
                                    
    1
                              V
    (L1) = .Cells(R1).Value
                              V
    (L2) = .Cells(R2).Value
                              V
    (L3) = "{" & .Cells(R3).Value
                End 
    If
            
    Next
                    
    If L Then V(L3) = V(L3) & "}"
        
    End With
             Application
    .ScreenUpdating False
        With Worksheets
    ("output")
            .
    UsedRange.Offset(1).Clear
            
    .[A2:C2].Resize(L).Value V
        End With
             Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-23-2017 at 10:49 PM. Reason: optimization …

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Generate array from multiple rows

    Try this
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  5. #5
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Thank you everyone all of these work perfectly.

    I should have thought this through much better as I have changed the scope of this.

    I would like the curly brackets into quotes.

    And I also need an equal number of comma separators even of there is no data present. The delimiter will need to be there even if it's blank. And no spaces before or after the comma delimiter.

    I will import this into SQL via csv and the script reads all fields equally so if the max is 4 data points and one of the rows only has 2 data points, I will need 4 comma delimiters anyway.

    Please see attached sample data and output.

    Thank you so so much!!!
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Thank you so much jindon this works perfectly!

  8. #8
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Is there any way to optimize this? Excel keeps crashing and I can't process even just 50,000 rows.

    By the way I'm using Excel 2016

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Perfect jindon! I tried it with 700K rows and it works flawlessly.

    Thank you!

  11. #11
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Hi jindon I hate to keep doing this to you but I found another issue I didn't notice before. I can do this with a new request if it's too difficult revising your perfectly working script.

    I have duplicate data in Column C and I need to remove it and keep only 1 instance.

    So it would work exactly as you've written it but it would take into consideration duplicates within the group.

    Please see attached for example of the duplication. It is based on Column A or Column B grouping and you'd remove Column C duplicates (keeping only 1 instance) within the group.

    Thank you so so much!
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    Ah, I see
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Thank you jindon it works great but I'm having the crashing issue again. Is there any way to optimize it for a large data set?

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    What do you mean by "crush"?

    I've just tested the code with about 800000 rows and took about 15 sec, but no "crush".

  15. #15
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    thank you so much jindon for working on this.

    I'm not sure what I am doing wrong but excel keeps crashing now with the new script.

    I'll PM you with the file I am working with (I don't want it to be pubic). If you have a minute, please run the script on the file so you can see what I mean.

    Thank you very very much I truly appreciate your time.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    You have ERROR value.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    YAY it works now

    Thank you, thank you, thank you!!!

  18. #18
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    Hello,

    Is it possible to revise this so it does not take into consideration the equal number of delimiters?

    It would only return the delimiters that are present.

    So the output would look like this:

    One,Two
    One,Two,Three
    One,Two,Three,Four
    One,Two,Three,Four,Five

    NOT like this which is what it currently does:

    One,Two,,,
    One,Two,Three,,
    One,Two,Three,Four,
    One,Two,Three,Four,Five

    Thank you!

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Generate array from multiple rows

    Change
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Generate array from multiple rows

    You're a god. Works perfect. Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] generate multiple rows with vba
    By ROHAN999 in forum Excel Programming / VBA / Macros
    Replies: 54
    Last Post: 10-12-2016, 07:54 PM
  2. Replies: 7
    Last Post: 05-07-2016, 10:34 PM
  3. Replies: 1
    Last Post: 02-16-2016, 07:51 PM
  4. Replies: 7
    Last Post: 04-23-2015, 10:02 AM
  5. [SOLVED] Generate multiple invoices fetching data from rows of a sheet
    By devang.vakharia in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-12-2013, 08:14 AM
  6. Generate List of Matching Rows from multiple tabs
    By xenocide8d in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-02-2010, 12:52 AM
  7. generate multiple rows based on cell value
    By Theresa in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-25-2005, 06:21 PM

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