PC Review


Reply
Thread Tools Rate Thread

Counting Highlighted Rows

 
 
Phil H
Guest
Posts: n/a
 
      17th Nov 2009
I am highlighting rows beyond what I see on screen. Can someone give me a
macro that counts the number of highlighted rows.
 
Reply With Quote
 
 
 
 
Luke M
Guest
Posts: n/a
 
      17th Nov 2009
Sub HowMany()
MsgBox Selection.Rows.Count
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Phil H" wrote:

> I am highlighting rows beyond what I see on screen. Can someone give me a
> macro that counts the number of highlighted rows.

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      17th Nov 2009
By "highlighting", do you mean "selecting"? If so, then give this macro a
try (it will handle both contiguous and non contiguous selections)...

Sub CountRowsInSelection()
Dim A As Range, U As Range
For Each A In Selection.Areas
If U Is Nothing Then
Set U = A.EntireRow
Else
Set U = Union(U, A.EntireRow)
End If
Next
MsgBox Intersect(U, Columns(1)).Count
End Sub

--
Rick (MVP - Excel)


"Phil H" <(E-Mail Removed)> wrote in message
news:FCB4462D-FD45-4EC9-892F-(E-Mail Removed)...
>I am highlighting rows beyond what I see on screen. Can someone give me a
> macro that counts the number of highlighted rows.


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      17th Nov 2009
Your code will not work if the Selection contains non contiguous areas with
non overlapping rows (for example, C3:F9 and H14:M20).

--
Rick (MVP - Excel)


"Luke M" <(E-Mail Removed)> wrote in message
news:36C0418F-099F-4D77-AE16-(E-Mail Removed)...
> Sub HowMany()
> MsgBox Selection.Rows.Count
> End Sub
> --
> Best Regards,
>
> Luke M
> *Remember to click "yes" if this post helped you!*
>
>
> "Phil H" wrote:
>
>> I am highlighting rows beyond what I see on screen. Can someone give me
>> a
>> macro that counts the number of highlighted rows.


 
Reply With Quote
 
Phil H
Guest
Posts: n/a
 
      17th Nov 2009
Works great. Thanks, Luke.

"Luke M" wrote:

> Sub HowMany()
> MsgBox Selection.Rows.Count
> End Sub
> --
> Best Regards,
>
> Luke M
> *Remember to click "yes" if this post helped you!*
>
>
> "Phil H" wrote:
>
> > I am highlighting rows beyond what I see on screen. Can someone give me a
> > macro that counts the number of highlighted rows.

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      17th Nov 2009
I'm guessing, then, that you will never have selections composed of
non-contiguous areas. For future consideration, you should really mention
such things in your questions when you ask them... the more information you
give about your set up and what you want to do, the better able we are to
give you solutions that do what you are looking for.

--
Rick (MVP - Excel)


"Phil H" <(E-Mail Removed)> wrote in message
news:F69D5E8D-E762-4312-A114-(E-Mail Removed)...
> Works great. Thanks, Luke.
>
> "Luke M" wrote:
>
>> Sub HowMany()
>> MsgBox Selection.Rows.Count
>> End Sub
>> --
>> Best Regards,
>>
>> Luke M
>> *Remember to click "yes" if this post helped you!*
>>
>>
>> "Phil H" wrote:
>>
>> > I am highlighting rows beyond what I see on screen. Can someone give
>> > me a
>> > macro that counts the number of highlighted rows.


 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      18th Nov 2009
If highlighting rows means selecting entire rows, I think this would be
enough.

MsgBox Intersect(Selection, Columns(1)).Count

If not entire rows, then

MsgBox Intersect(Selection.EntireRow, Columns(1)).Count

Keiji

Rick Rothstein wrote:
> By "highlighting", do you mean "selecting"? If so, then give this macro
> a try (it will handle both contiguous and non contiguous selections)...
>
> Sub CountRowsInSelection()
> Dim A As Range, U As Range
> For Each A In Selection.Areas
> If U Is Nothing Then
> Set U = A.EntireRow
> Else
> Set U = Union(U, A.EntireRow)
> End If
> Next
> MsgBox Intersect(U, Columns(1)).Count
> End Sub
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th Nov 2009
> If not entire rows, then
>
> MsgBox Intersect(Selection.EntireRow, Columns(1)).Count


Yes, that works fine and is **much** better than the code I posted!

--
Rick (MVP - Excel)


"keiji kounoike" <"kounoike A | T ma.Pikara.ne.jp"> wrote in message
news:OOwt$(E-Mail Removed)...
> If highlighting rows means selecting entire rows, I think this would be
> enough.
>
> MsgBox Intersect(Selection, Columns(1)).Count
>
> If not entire rows, then
>
> MsgBox Intersect(Selection.EntireRow, Columns(1)).Count
>
> Keiji
>
> Rick Rothstein wrote:
>> By "highlighting", do you mean "selecting"? If so, then give this macro a
>> try (it will handle both contiguous and non contiguous selections)...
>>
>> Sub CountRowsInSelection()
>> Dim A As Range, U As Range
>> For Each A In Selection.Areas
>> If U Is Nothing Then
>> Set U = A.EntireRow
>> Else
>> Set U = Union(U, A.EntireRow)
>> End If
>> Next
>> MsgBox Intersect(U, Columns(1)).Count
>> End Sub
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Selected/Highlighted Rows Phil H Microsoft Excel Programming 7 28th Jan 2010 08:31 PM
Counting highlighted cells Kassie Microsoft Excel Misc 2 8th May 2008 04:50 PM
Counting highlighted cells? =?Utf-8?B?Sm9zaCAtIFdlc3RmaWVsZCBBdXN0cmFsaWE=?= Microsoft Excel Misc 2 20th Apr 2005 09:20 AM
counting highlighted cells Dragonstear Microsoft Excel Misc 1 17th Oct 2003 05:10 AM
counting a highlighted cell Dragonstear Microsoft Excel Programming 1 17th Oct 2003 03:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:10 PM.