ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counting Highlighted Rows (https://www.excelbanter.com/excel-programming/436307-re-counting-highlighted-rows.html)

keiji kounoike

Counting Highlighted Rows
 
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


Rick Rothstein

Counting Highlighted Rows
 
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
...
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




All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com