+ Reply to Thread
Results 1 to 14 of 14

Using Countif with object properties.

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Using Countif with object properties.

    A checkbox in my worksheet has the following properties:

    Please Login or Register  to view this content.
    .Value = xlon as I understand means the check-box is checked

    Is it possible to use Application.WorksheetFunction.Countif to count, in a range of tick-box objects, whether they have the 'xlon' value?
    Using:
    Please Login or Register  to view this content.
    I realise that I might be making some naive mistakes with this code - but basically I want to count using the inherent properties of the check-boxes, rather than count from the linked cells.

    I hope this makes sense.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.

    just check the property against xlOn

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Using Countif with object properties.

    LinkedCell property only appears for activeX checkboxes, hence not in the CheckBoxes collection.

    try:
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.

    not true. This worked for me when a Forms control checkbox was placed on the worksheet

    Please Login or Register  to view this content.

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Using Countif with object properties.

    Quote Originally Posted by Andy Pope View Post
    not true. This worked for me when a Forms control checkbox was placed on the worksheet
    Yes it works if Forms check boxes were used, no doubt about that, but he is using ActiveX check boxes.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.



    Why say this then
    LinkedCell property only appears for activeX checkboxes, hence not in the CheckBoxes collection.
    why do you say he is using ActiveX, I can not see that explicitly mentioned anywhere (although I could be mistaken).

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Using Countif with object properties.

    Because LinkedCell only appears for ActiveX checkboxes. In Forms checkboxes the equivalent is called ControlSource

    Edit: Ok I guess I was wrong, seems like LinkedCell property appears through VBA editor for both.
    Last edited by millz; 09-17-2013 at 08:34 AM.

  8. #8
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Using Countif with object properties.

    Thanks both - I can confirm that I'm using Form Controls - and the code supplied works perfectly. I avoid activeX because I have yet to get my head round them to the same extent - also to link cells to them I have to right click and choose properties, as opposed to simply specifying the linked cell in the toolbar - small thing, but the time spent really adds up!

    There's a couple amongst my 361 check-boxes(!) which seem immune to the count - as in, they don't move up or down when ticked - is there anything obvious I'm missing which could cause the issue?

    Also - if you don't mind - can I alter the code to specify a certain range - so that I count 1 To 10, for example?

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.

    you could alter the loop assuming the Index order of the controls is suitable.

    Please Login or Register  to view this content.
    Or you may need to check the controls name or it's location on the worksheet. Hard to say without example file. Same for the 'immune' controls. maybe you can list out where they are linked to incase you have controls linking to the same cell.

  10. #10
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Using Countif with object properties.

    Andy - I've attached an example workbook which I've knocked together to illustrate the situation your code is helping me to aaddress:

    I have made 6 identical sheets - these are sheets for each user to fill in. I've pasted in an example question.

    The reason I asked for your code is so that I can quickly tally certain boxes. For example, I want to know how many people ticked 'None' for the sentencing occasion on the sheet. So that would be counting a specific range of boxes, 1 on each sheet.
    As you can see it's easy to make some tallies manually when there's as few sheets and questions as in the worksheet I posted - but it becomes much harder when you have 360 boxes on each sheet and 100 sheets!
    Attached Files Attached Files

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.

    could not easily test example as the controls are all linked to a different workbook.

    Please Login or Register  to view this content.
    If the choices are mutally exclusive should you not be using Option buttons instead?

  12. #12
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Using Countif with object properties.

    Andy that's incredible - it really does work like a dream

    In theory, if I have five sheets with 1 check-box in each, all called 'Check box 1' (excel seems to restart the count for each different worksheet), could this macro count For each Worksheet, whether check-box 1 is ticked, and then produce a total? I.e only box 1.

    You make a good point about Option buttons - however, I chose a bad example because most of my questions are not mutually exclusive - e.g(fictional), "what are your symptoms?"

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Using Countif with object properties.

    If you want to test the controls name then

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Using Countif with object properties.

    Ah - I didn't see where you'd written 'None' in the code at first.

    I am positively gleeful right now - I can't tell you how much this helps me/ how much you've taught me!

    Thanks so much

+ 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. Macro code to change the ActiveX Control Object Properties
    By jackgan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2013, 02:31 PM
  2. Zoom Affecting Object Properties
    By throtmorton in forum Excel General
    Replies: 0
    Last Post: 08-28-2006, 11:39 AM
  3. [SOLVED] countif counting properties
    By Darryl in forum Excel General
    Replies: 5
    Last Post: 01-04-2006, 12:15 PM
  4. [SOLVED] Chart Object Properties Problem
    By Lori Villarreal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-20-2005, 11:05 AM
  5. HELP! Object, Properties & Methods
    By dee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2005, 07:06 PM

Tags for this Thread

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