PC Review


Reply
Thread Tools Rate Thread

Count of rows - discontiguous selection

 
 
xp
Guest
Posts: n/a
 
      15th Oct 2009
Hi,

I need a code that will count the number of rows in a selection; BUT, the
selection has multiple sets of discontiguous ranges of cells each with a
various number of rows.

I thought, Selection.Rows.Count would do it, but it doesn't...

Thanks for the help...
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      15th Oct 2009
Try this code...

Dim R As Range, TotalRows As Long
......
......
For Each R In Selection.Areas
TotalRows = TotalRows + R.Rows.Count
Next
MsgBox "That selection has " & TotalRows & " rows in it."

--
Rick (MVP - Excel)


"xp" <(E-Mail Removed)> wrote in message
news2A91AF0-7368-4B0D-A7F2-(E-Mail Removed)...
> Hi,
>
> I need a code that will count the number of rows in a selection; BUT, the
> selection has multiple sets of discontiguous ranges of cells each with a
> various number of rows.
>
> I thought, Selection.Rows.Count would do it, but it doesn't...
>
> Thanks for the help...


 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      15th Oct 2009
Try this:

Sub IAmTheCount()
ic = 0
irlast = 0
For Each r In Selection
ir = r.Row
If ir <> irlast Then
ic = ic + 1
irlast = ir
End If
Next

MsgBox ic
End Sub

--
Gary''s Student - gsnu200907


"xp" wrote:

> Hi,
>
> I need a code that will count the number of rows in a selection; BUT, the
> selection has multiple sets of discontiguous ranges of cells each with a
> various number of rows.
>
> I thought, Selection.Rows.Count would do it, but it doesn't...
>
> Thanks for the help...

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Oct 2009
Dim myRng As Range
Set myRng = Intersect(ActiveSheet.Columns(1), Selection.EntireRow)
MsgBox myRng.Cells.Count

If the discontiguous areas could be in overlapping rows, this may not give you
want you want.

A1:A13, B2:B5, C12:C13

would give 13.



xp wrote:
>
> Hi,
>
> I need a code that will count the number of rows in a selection; BUT, the
> selection has multiple sets of discontiguous ranges of cells each with a
> various number of rows.
>
> I thought, Selection.Rows.Count would do it, but it doesn't...
>
> Thanks for the help...


--

Dave Peterson
 
Reply With Quote
 
K_Macd
Guest
Posts: n/a
 
      17th Oct 2009
Here is another variation

AreaNo = 1
Msg = ""
For Each Area In Selection.Areas
Msg = Msg & "The area " & AreaNo & " selection contains " & _
Area.Rows.Count & " rows." & vbCrLf
AreaNo = AreaNo + 1

Next Area

MsgBox Msg

--
Ken
"Using Dbase dialects since 82"
"Started with Visicalc in the same year"


"Gary''s Student" wrote:

> Try this:
>
> Sub IAmTheCount()
> ic = 0
> irlast = 0
> For Each r In Selection
> ir = r.Row
> If ir <> irlast Then
> ic = ic + 1
> irlast = ir
> End If
> Next
>
> MsgBox ic
> End Sub
>
> --
> Gary''s Student - gsnu200907
>
>
> "xp" wrote:
>
> > Hi,
> >
> > I need a code that will count the number of rows in a selection; BUT, the
> > selection has multiple sets of discontiguous ranges of cells each with a
> > various number of rows.
> >
> > I thought, Selection.Rows.Count would do it, but it doesn't...
> >
> > Thanks for the help...

 
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
datatable rows count and dataview count differ John Hui Microsoft ADO .NET 4 3rd Aug 2010 10:26 PM
Error with Selection.CurrentRegion.Rows.Count? KenY Microsoft Excel Programming 2 21st Apr 2010 11:01 AM
Help: Discontiguous text selection no longer works (ctrl-select) =?Utf-8?B?dmlrZXM=?= Microsoft Word Document Management 1 15th May 2006 08:37 PM
Re: how do i count rows, and count them by color or a highlight? blue. Frank Kabel Microsoft Excel Worksheet Functions 0 9th Sep 2004 10:05 PM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 Microsoft ASP .NET 2 6th Jun 2004 08:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 PM.