ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do i know how many rows has been selected? (https://www.excelbanter.com/excel-programming/333835-how-do-i-know-how-many-rows-has-been-selected.html)

OKLover

How do i know how many rows has been selected?
 
When i used the CTRL and SHIFT key to multiple select some rows, ex: Row 1,
5, 7,11. How do i to check how many rows has been selected? like return 4.



Norman Jones

How do i know how many rows has been selected?
 
Hi OKLover,

Try:

Sub Tester1()
Dim rng As Range, Ar As Range, rw As Range
Dim iCtr As Long

Set rng = Selection

For Each Ar In rng.Areas
For Each rw In Ar.Rows
iCtr = iCtr + 1
Next rw
Next Ar

MsgBox "There are " & iCtr & " rows in the selection"

End Sub

---
Regards,
Norman



"OKLover" wrote in message
...
When i used the CTRL and SHIFT key to multiple select some rows, ex: Row
1, 5, 7,11. How do i to check how many rows has been selected? like return
4.




Dana DeLouis[_3_]

How do i know how many rows has been selected?
 
One option if you do in fact have entire rows selected:

N = Intersect(Selection, Columns(1)).Cells.Count
or to be safe:
N = Intersect(Selection.EntireRow, Columns(1)).Cells.Count

HTH
--
Dana DeLouis
Win XP & Office 2003


"OKLover" wrote in message
...
When i used the CTRL and SHIFT key to multiple select some rows, ex: Row
1, 5, 7,11. How do i to check how many rows has been selected? like return
4.




OKLover

How do i know how many rows has been selected?
 
Wonderful! you are so COOOOOOOOL ~


"Dana DeLouis" bl...
One option if you do in fact have entire rows selected:

N = Intersect(Selection, Columns(1)).Cells.Count
or to be safe:
N = Intersect(Selection.EntireRow, Columns(1)).Cells.Count

HTH
--
Dana DeLouis
Win XP & Office 2003


"OKLover" wrote in message
...
When i used the CTRL and SHIFT key to multiple select some rows, ex: Row
1, 5, 7,11. How do i to check how many rows has been selected? like
return 4.







All times are GMT +1. The time now is 07:23 PM.

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