Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Count of rows - discontiguous selection

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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Count of rows - discontiguous selection

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" wrote in message
...
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...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Count of rows - discontiguous selection

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...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Count of rows - discontiguous selection

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Count of rows - discontiguous selection

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error with Selection.CurrentRegion.Rows.Count? KenY Excel Programming 2 April 21st 10 11:01 AM
Discontiguous Chart Source Ladymuck Excel Programming 6 January 2nd 07 10:47 AM
Is it possible to plot discontiguous cells? Peter Bernadyne Charts and Charting in Excel 8 May 11th 06 09:45 PM
Object Type of a selection... counting rows in a selection Acid-Sky[_2_] Excel Programming 3 August 23rd 05 09:53 AM
discontiguous ranges in charts Pilgrim Excel Programming 1 July 3rd 04 05:53 PM


All times are GMT +1. The time now is 12:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"