+ Reply to Thread
Results 1 to 8 of 8

How to sort TreeView1 child nodes in ascending order?

  1. #1
    Registered User
    Join Date
    02-19-2023
    Location
    London
    MS-Off Ver
    2007
    Posts
    27

    How to sort TreeView1 child nodes in ascending order?

    Hi all,

    I am making an application to display and eventually analyse horse racing data (hopefully to save me time in the future) that I obtain from a Python web scraper that saves into a csv file(s). I have created a UserForm with a TreeView to display race courses and race times, which I plan to display the data in a ListView on child node click event, and then hope to create some magic to compare current race data with historical race data, and highlight positive and negative criteria by coloring cells appropriatly, so to analyse a race at a glance.

    I am currently able to import the data into a new sheet from userform_initialize(), get the race course names to display as my parent nodes in the TreeView1, as well as the race times as my child nodes. I must say, ChatGPT has been awesome up until this point, where I would like to now sort the race time child nodes into ascending order, earliest to latest, but have been going round in circles for a couple of days now being hit with different error, usually somthing not found.

    In the current version after the parent node Loop, the most succinct piece of code I have been working with is;

    Please Login or Register  to view this content.
    But for some reason it cannot find the .Sort method. When I write childNodes. Sort is not in the list. I can get Child or Children, or even sometimes Sorted, but none of these work, producing additional errors. childNodes.Child. doesn't work either as I assume the Child method doesnt have a sort method, although I think it has childNodes.Child.Add method, you'd have though it would have Sort!?

    I'll attach my full project but have removed this section of code because for some reason it keeps going crazy when I try and save the workbook with this code commented out, and things keep disapearing.

    If anyone can shed some light and point me in the right direction it would be very much appricated.

    TIA

    P.s. Just incase, FYI, I have made sure I have references checked in tools/references; MS Common controls, MS scripting runtime, MS VB for applications Extensibility 5.3. These are all solutions I found for my missing method problems, but none of them worked unfortunately.
    Attached Files Attached Files
    Last edited by BrovashiftExcel; 04-29-2023 at 01:32 PM.

  2. #2
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How to sort TreeView1 child nodes in ascending order?

    Without reading or looking into your file, sort the dataset itself before you read in

  3. #3
    Registered User
    Join Date
    02-19-2023
    Location
    London
    MS-Off Ver
    2007
    Posts
    27

    Re: How to sort TreeView1 child nodes in ascending order?

    Quote Originally Posted by JEC. View Post
    Without reading or looking into your file, sort the dataset itself before you read in
    Hi, do you mean sort it in the csv data file before importing it? So using the excel filter option in the ribbon at the top first, and then importing it that way? Problem with that is I will be running a fresh web scrape on a daily basis and manually sorting the data before importing it kinda defeats the object of the project, trying to make my life easier by automating this process.
    I already import the race course names to the parent treeview nodes, without sorting beforehand. But when trying to do something similar with the child nodes I keep getting errors. Actually that not accurate, because I am doing something similar to obtain the race times as the child nodes. Its just the sorting them I am struggling with. This is my first VB project, I am more familiar with C#, but this created other issues when working with a python script and C# Winforms. And as the data is already in excel format, and excel have userforms, I thought this would be the most straight forward approach.
    Last edited by BrovashiftExcel; 04-29-2023 at 02:48 PM.

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How to sort TreeView1 child nodes in ascending order?

    You could do the sort automatically within the macro.
    Since you are scraping the data, is Power query an option too

  5. #5
    Registered User
    Join Date
    02-19-2023
    Location
    London
    MS-Off Ver
    2007
    Posts
    27
    Quote Originally Posted by JEC. View Post
    You could do the sort automatically within the macro.
    Since you are scraping the data, is Power query an option too
    Ah yes I see what you mean now. So Im importing the data from an external csv file within the project folder, and creating and pasting it into a new sheet2 in my raceAnalyser.xlsm in the initialize method. As well as loop through to get the race course names and race times (removing duplicates)... then trying to sort.
    Terminating the userform deletes the data and the newly created sheet2.

    So alternatively, import the data when form loaded as I am, then sort the data... then loop through to populate the treeview nodes with the sorted data. Is that what you mean?
    That might work...

    Ive never used PowerQuery, my excel skills are mediocre, but I know someone who uses PQ and does some really clever stuff with it.

  6. #6
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How to sort TreeView1 child nodes in ascending order?

    Yes that is what I mean

  7. #7
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How to sort TreeView1 child nodes in ascending order?


  8. #8
    Registered User
    Join Date
    02-19-2023
    Location
    London
    MS-Off Ver
    2007
    Posts
    27

    Re: How to sort TreeView1 child nodes in ascending order?

    I have sorted this now. If anyone finds it useful I have posted the code here;https://pastebin.com/LRWFXVfK

    Sorting the data before adding it to the treeview did not work in the end because even though the times were ascending, the race courses were all over the place and had repeats containing each race time, as oppsoed to single race courses and repeated race times. Sorted now anyway, but now I have a new issue with some random child nodes "Unable to get the Match property of the WorksheetFunction class".

    I'll make a new thread for that though, keep things neat.

    Cheers

+ 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] Treeview - Add Child Nodes based on Sheet to Parent Node
    By judeprem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2022, 10:25 AM
  2. [SOLVED] Get a list of all selected child nodes of a treeview
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2019, 01:24 AM
  3. Finding Values in Nodes and Child Nodes in XML SOAP POST
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2018, 11:33 AM
  4. Sort the final digits and sort in ascending order
    By jorel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2014, 11:58 AM
  5. [SOLVED] Sort Ascending order
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2013, 02:27 PM
  6. [SOLVED] Sort in ascending order
    By Dibbley247 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-17-2013, 12:30 AM
  7. sort ascending order
    By iscar_marius in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-11-2009, 11:00 AM

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