+ Reply to Thread
Results 1 to 38 of 38

Sorting data from one general column to multiple specific columns

  1. #1
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Sorting data from one general column to multiple specific columns

    Hoping this is possible.
    I have attached two sheets. Sheet 1 is considered 'Raw Data' which is how I get the text file from the County Assessor. They define each of the three columns with an identifier (Imp_pn_id2) which is a parcel number, imprv_det_type which defines what the improvement is, and calc_area which gives the size or area of the improvement. A specific parcel may have more than one of the same type improvement (ie two porches).

    What I am hoping to achieve is displayed on Sheet 2 considered the 'Sorted Results'. The column names in this table are only the ones that were present in this specific 'Raw Data' table, as there are quite a few more in the ‘real’ file. I am hoping to have one row for each unique parcel number with the improvements sorted into columns. Where a parcel has more than one of the same type improvement, I have added them and presented the total. ie P10000549652 has two CPOR (Covered Porch) of 9 each which is represented as 18 in its respective column for Sheet 2 ‘Sorted Results’.

    The specific file I took this sample from has approximately 250,000 rows and 70,000 unique parcel numbers.

    While my experience is very limited, at best, I am hoping for a macro because of the file size.

    Any help, direction, or advice is appreciated.
    Attached Files Attached Files
    Last edited by abuchan; 04-01-2011 at 07:20 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Sorting data from one general column to multiple specific columns

    Hi

    Have you tried using a PIVOT TABLE?

    rylo

  3. #3
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    No I have not. If you think that would be an efficient way to accomplish what I am hoping for, I will do some research in the am and see if I can make it work. My knowlege with Excel comes from what I have picked up from this site, which is much appreciated.

    Thank you, I will give it a good look in the morning.

    Alec.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi abuchan,
    you could use..
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste
    To run the Excel VBA code:
    Please Login or Register  to view this content.
    Choose Tools | Macro | Macros
    Select a macro in the list, and click the Run button
    Last edited by pike; 03-28-2011 at 01:31 AM. Reason: remove debug.print
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    or to add vaules with no entries
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    Thank you, it worked wonderfully on the sample. I will try it this afternoon on the 'real' set of data. Do you suspect any memory limitations with the dictionary?

    Thank you again, I will respond further, later today.

    Alec.

  7. #7
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I couldn't wait until later, I had to try it. As I stated in the original post, this sheet has almost 250,000 rows. I ran the macro and it thought for about five seconds and the following window appeared: Run-time error '457': This key is already associated with an element of this collection. When I debugged it, the following code was highlighted:
    Please Login or Register  to view this content.
    Thank you for your effort, it is appreciated.

  8. #8
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I have run some tests on the 'real' file. With 100 rows, it seems to work well. With 1,000 rows, it seems to work well. With 5,000 rows, it seems to work well. With 6,000 rows, it gives me the error from above. Went back to 5,000 rows and it seemed to work well again.

    I then ran the data from rows 5,000 to 6,000 and it seems to work well. I ran the data from rows 5,000 to 10,000 and it worked well. I ran the data from row 5,000 to 11,000 (6,000 rows) and it seemed to work well. Tried rows 5,000 to 20,000 and it seems to work well.

    Now I am even more confused than before...

    Your thoughts are appreciated.
    Last edited by abuchan; 03-28-2011 at 11:49 AM. Reason: more information

  9. #9
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I completed some further testing. I was able to locate the rows which were causing the first issue. Once I eliminated them, it was able to run from 1 to 8,000 without issue. when I tried 1 to 10,000 it gave me the same error. The four lines I removed looked just like any of the others.

    Line 5833 P10386251078 MA 2787
    Line 5834 P10386251078 AGAR 506
    Line 5835 P10386251078 CPOR 110
    Line 5836 P10386251078 CPOR 48
    Line 5837 P10386251078 MPS 80

    I can put a link up to download the 'real' file if it helps.

    I am using the lower of the two Macros as all the parcel numbers need to be represented.

    Thank you.
    Last edited by abuchan; 03-28-2011 at 03:45 PM. Reason: additional

  10. #10
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I have made the 'real' file available at :
    http://www.vitalsoft.com/~bradk/SkagitSortMacro.zip
    Thanks.

  11. #11
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Sorting data from one general column to multiple specific columns

    Hi

    Ran this to about 50k record mark in your full file, and got no errors to that point.

    Please Login or Register  to view this content.
    rylo

  12. #12
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I just finished running the Macro. 3 hours, 8 minutes, 56 seconds. After a slight panic attack, I located the results on Sheet 3. Upon first glance, I am very optimistic. I will continue to review it tonight.

    Thank you very much.

    Alec.

  13. #13
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    It seems to work very well. I went ahead and tried the lower macro on a sheet with text that does not (shouldn't anyway) repeat. It seemed to work on that as well. I am attaching a sample file without repeats to see if you think the macro will work, all the way through, or if it would need to be adjusted.

    Thank you for your effort, this is fantastic!

    Much appreciated, Alec.
    Last edited by abuchan; 03-29-2011 at 08:40 AM.

  14. #14
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Sorting data from one general column to multiple specific columns

    Hi

    new file has a very different structure. Exactly what should the output look like? Or what 3 columns are you trying to use to create your matrix?

    rylo

  15. #15
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi abuchan,
    This should run in a few minutes
    in stead of using b() to store the data it writes to the sheet2 and saves in it the dic1
    dic1 and dic2 are then reference sheet2 cells
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    Rylo,

    I think I was too sleepy. I uploaded the file before massaging it. Here it is. I ran your Macro on it and it seems to work very nicely with text.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    Pike,

    Wow. took less than two minutes! The results look amazing. It ended up with the same amount of unique parcel numbers but a different amount of columns which I will look at later this morning. Your work amazes me.

    Thank you.

  18. #18
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I did some more testing and everything appears really good. It picked up about 10 other columns that were missed on earlier versions. I am going to process the data with it now and if all goes well, I will be able to close the thread. Nicely done, thank you.

  19. #19
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    I'm curious about the speed of this one:

    Please Login or Register  to view this content.



  20. #20
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    I won't be able to look at it until this evening as my computer will be tied up until then. However, I supplied a link, several posts above, where you can download the actual file from me and run it. The data is exactly the same as I have here. There is just under 250,000 rows and you should end up with 62,651 unique parcel numbers. I would be interested to hear what you end up with. Otherwise, I will try it this evening as it is only 1:20 pm here.

    Upon submitting my post, I noticed that you don't have 2007, sorry. I will run it tonight and give you a heads-up.

    Thanks,
    Alec.
    Last edited by abuchan; 03-29-2011 at 04:22 PM. Reason: more...

  21. #21
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    abuchan
    cleaned up code
    Please Login or Register  to view this content.
    @snb mismatch error on
    Please Login or Register  to view this content.
    Last edited by pike; 03-30-2011 at 02:12 AM.

  22. #22
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    I came up with a variation, that is less sensitive to large arrays (tested on 65536 rows).

    Please Login or Register  to view this content.

  23. #23
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi snb,
    after seven min mismatch on
    Please Login or Register  to view this content.

  24. #24
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    @Pike thanks for testing

    It appears that match has a limit of 5461 in an array.
    So I came up with something new (after which I intend to explore your dictionary-method)
    The following code assumes column A to be sorted.
    I used the 'real' data, but couldn't test more than 65536 rows.
    The result in this system: 9,5 seconds
    Please Login or Register  to view this content.
    Last edited by snb; 03-31-2011 at 05:40 AM.

  25. #25
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    the dic in 52 seconds but has more loops

    You should free up some memory by using Option explicit and declaring arrays as variables ect.. these make all the difference and will make it quicker.

  26. #26
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    @ Pike

    The speed is 9,5 seconds (<20% of your result)
    Option explicit nor declaring will improve that. You can't 'free' memory by using option explict, nor by declaring variables.

  27. #27
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Dude from Mrocrosoft - "Performance Advantage. Setting Option Explicit has the advantage of forcing type inference to be made at compile time instead of run time. This improves performance"

    When declaring variables, VBA assigns particular amount
    of memory to that variable depending on its data type.
    Typically, 32bits for Integer values etc… But if you are
    looking to allocate memory while run-time, that will reduce
    program’s performance.

    But well done for getting 5.2s with your code as I get an error on
    Please Login or Register  to view this content.
    I'll try sorting again
    Anyway we dont want to scare abuchan with this banter ..

    Yes dic are good as they can store arrays and retrevie change ect......

  28. #28
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    Then you'd better put dots before cells:

    .Columns(1).AdvancedFilter xlFilterCopy, , .Cells(1, 60), True
    Last edited by snb; 03-31-2011 at 06:17 AM.

  29. #29
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi snb,
    found the error and on this machine 124s

  30. #30
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    On the oldest available system (Pentium II; 350Mhz) it took 70seconds.

    You'd better check for viruses

  31. #31
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    You are right about option explicit and no difference in speed due to the variable checking but you will free memory .
    yep, i better check for bugs, How long did the dic code take to run on your machine?

  32. #32
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    On the same machine it took 182 seconds; but the result isn't what it should be: there's only 1 column filled in sheet2.


    I wonder why you didn't use a collection:

    Please Login or Register  to view this content.

  33. #33
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi,
    Many reasons; Speed of dic, Duplicate values will error and you cant see if it exists in the collection, how you use the array in collection if you cant retrieve its key and
    Collection Item property is read-only.

  34. #34
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sorting data from one general column to multiple specific columns

    Please Login or Register  to view this content.
    reduced writing operations
    reduced number of loops
    Last edited by snb; 03-31-2011 at 05:02 PM.

  35. #35
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    "Scared", no. "Concerned", yes. While I enjoy your conversation and marvel at your 'magic', I used the last code provided by Pike and 'was' happy with the results. Does the conversation above suggest the results to not be accurate? Your help and guidance is much appreciated.

    Thank you.

  36. #36
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Hi abuchan
    No, more about the many different ways to do anything, Coding Practices, size limits with arrays and functions.
    Its all good.
    Last edited by pike; 04-01-2011 at 05:33 PM.

  37. #37
    Forum Contributor
    Join Date
    11-09-2008
    Location
    Washington State
    MS-Off Ver
    2007
    Posts
    164

    Re: Sorting data from one general column to multiple specific columns

    Thank you for all your effort and work. Looks like magic to me!

  38. #38
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Sorting data from one general column to multiple specific columns

    Jindon did all the hard work I just adapt his concepts

+ 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