+ Reply to Thread
Results 1 to 6 of 6

Count number of selected rows

  1. #1
    Registered User
    Join Date
    08-22-2008
    Location
    UK
    Posts
    13

    Count number of selected rows

    How do I count the number of ENTIRE rows selected on a worksheet? Using Selection.Rows.Count returns 1 if I don't highlight the entire row. I want the result to be 0 if an entire row has not been selected.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count number of selected rows

    No doubt a few routes... one might be:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-22-2008
    Location
    UK
    Posts
    13

    Re: Count number of selected rows

    Thanks for that, it works great! Although I must admit I'm not sure I understand how it works??

  4. #4
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Count number of selected rows

    Also
    Please Login or Register  to view this content.
    rgds
    johnjohns

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count number of selected rows

    Quote Originally Posted by sys_daw View Post
    Thanks for that, it works great! Although I must admit I'm not sure I understand how it works??
    Just checks to see if the column count of the range being iterated matches the column count of the sheet itself
    (in reality this latter value [sheet] should be calculated only once prior to commencement of loop given it's fixed (varies only by version))

    In VBA Boolean True coerced equates to -1 (as opposed to 1 in native XL) and False to 0 hence:

    1 - TRUE --> 2 (1--1)
    1 - FALSE --> 1 (1-0)
    on this basis I used an approach of

    Please Login or Register  to view this content.
    however you may find johnjohn's approach more logical/preferable, ie

    Please Login or Register  to view this content.
    you should use whichever makes most sense given you need to maintain !

  6. #6
    Registered User
    Join Date
    08-22-2008
    Location
    UK
    Posts
    13

    Re: Count number of selected rows

    Thanks both for your help, much appreciated.

+ 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