+ Reply to Thread
Results 1 to 18 of 18

count of unique listview items

  1. #1
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    count of unique listview items

    Hi,

    I have a listview ctrl from which i need to extract a summary.
    This listview is populated from access db. My listview is like:

    Strategy No: Strategy Group Project Name
    9 10 ABC Project
    13 12 CDS Enhancement and Support
    25 15 Delta Techops T&M
    41 10 bbbbbbbb
    41 15 cccccccccc

    I want the output to be entered to a new excel sheet in following output:

    Strategy Group Projects
    10 2
    12 1
    15 2
    Total Projects 5

    I'm able to transfer whole listview data to excel. But how to get the count of unique items from a column?
    i.e. count of each Strategy group is there in listview column 2?

    Pls help. Thanks in advance.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,058

    Re: count of unique listview items

    Can you upload example workbook?
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Hi,

    Thanks for the quick reply. Sample workbook is attached.
    The listview details are extracted to the excel. The output which i mentioned is where i'm stuck.
    Need to extract the details shown as in output from the listview. Thank you
    Attached Files Attached Files

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of unique listview items

    One way is this.
    Attached Files Attached Files
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Hi Fotis,

    Your solution works great. Thanks. but the output which i mentioned is the one which i've to extract from a listview ctrl in a seperate workbook(Summary sheet). Can u provide a vba code to extract the count of unique items from a listview ctrl?

    Thanks again

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of unique listview items

    Let me to understand correct.

    Do you need the results as i gave you in range D15:E19, IN another sheet in the same workbook or in another workbook? Why don't you use my formula for this?

    Do you want to do this using VBA? If yes, i hope some other will be able to helps you because VBA is not my best card! Or just to record in a macro the formulas that i used!

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,058

    Re: count of unique listview items

    Ah fotis, you never got tired of extra helper columns

    Here you can find two solution:
    1. Pivot
    2. Formula

    But also, as Fotis, I don't understand do you need in another Worksheet or another Workbook
    Attached Files Attached Files

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of unique listview items

    ...Ah fotis, you never got tired of extra helper columns
    Never! I just love these!

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: count of unique listview items

    Why not just query the database with a distinct clause? Seems easier and less work

  10. #10
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Hi,

    Distinct query cant be used since for one strategy group there may be more than one projects. I need to count how many times a specific strategy group is coming in Listview (2nd col) so that i can get the total projects assigned to that strategy group.

    Is there anything like Count(Listview1.Subitems(1) or something? Pls help

  11. #11
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of unique listview items

    What kind of help to offer you if you don't answer to our quesstions? I asked something in posr#6, Zbor offered 2 solutions.

    You just Ignore these and ask for help.

    What's about my questions and Zbor's solutions?

  12. #12
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Hi,

    Sorry for the confusion. I need VBA code to get the count of similar items in a column of Listview ctrl.
    All the solutions provided is for getting the result once its extracted to Excel.
    I am not looking for extracting whole data from listview and then apply formulas. Directly extract the count of similar items from Listview ctrl.

    Sorry for the confusion.

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: count of unique listview items

    If the listview is populated directly from sql, and you aren't adding or removing items in the listview then I guarantee 100% you can do this with a query. Can you post your SQL?

  14. #14
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Hi,

    Any suggestions?

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: count of unique listview items

    What about:

    PHP Code: 
    SELECT strategy_group
           
    Count(strategy_group
    FROM   (SELECT DISTINCT projectstrategy.strategy_no
                            
    projectstrategy.strategy_group
                            
    projectstrategy.strategy_a
                            
    projectstrategy.d_date
                            
    projectstrategy.voice_special_infra
                            
    projectstrategy.strategy_b
                            
    projectstrategy.strategy_c
                            
    projectstrategy.strategy_d
                            
    projectstrategy.strategy_e
                            
    project_details.* 
            
    FROM   projectstrategy
                   
    project_details 
            WHERE  project_details
    .window_of_ops IN " & sstring & " 
                   AND 
    project_details.state = ( '" & StateList & "' 
                   AND 
    projectstrategy.hours_of_ops '" & HourOps & "' 
                   
    AND projectstrategy.work_type '" & WorkT & "' 
                   
    AND project_details.penalty_clause 
                       
    projectstrategy.penalty_clause 
                   
    AND project_details.auto_redundancy 
                       
    projectstrategy.auto_redundancy 
                   
    AND projectstrategy.d_date '" & DelDate & "' 
                   
    AND project_details.voice_project 
                       
    projectstrategy.voice_special_infra 
                   
    AND projectstrategy.political_sensitiviy '" & PolS & "' 
                   
    AND projectstrategy.facility_vulnerability '" & FacS & "')  sub
    GROUP  BY strategy_group 
    The syntax may be off slightly, access sql isn't my thing

    The other way would be to count the groups as you loop through the listview when populating it - if you use a collection or dictionary, you can just increment the count each time an existing group is encountered
    Last edited by Kyle123; 01-07-2013 at 04:04 AM.

  17. #17
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: count of unique listview items

    Thank you for the reply. I will try it and let u know. Thanks again.

  18. #18
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Thumbs up Re: count of unique listview items

    Hi,

    This is what i was looking for. Works after a little bit of syntax change.
    Thank you so much..

+ 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