Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Non Contiguous range and loops

The following code returns 1 ,2 , 3, and 4 for the row
numbers of the non contiguous range rng.
Sub Code1 ()
Dim rng As Range
Set rng = Range("A1,A5,A7,A12")
For c = 1 To 4'
myArray(c) = rng.Cells(c).Row
Next
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Non Contiguous range and loops

David,

You don't say, but I guess you want the absolute row numbers, rather than
the relative row to the range?

If so, try this

Sub Code1()
Dim rng As Range, c, myArray(4)
Set rng = Range("A1,A5,A7,A12")
For c = 1 To 4 '
myArray(c) = rng.Areas.Item(c).Row
Next
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David" wrote in message
...
The following code returns 1 ,2 , 3, and 4 for the row
numbers of the non contiguous range rng.
Sub Code1 ()
Dim rng As Range
Set rng = Range("A1,A5,A7,A12")
For c = 1 To 4'
myArray(c) = rng.Cells(c).Row
Next
End Sub






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Non Contiguous range and loops

c = 1
for each cell in rng
myArray(c) = cell.row
c = c + 1
Next

-----------------

rng.cells(c)

is an offset from the top left cell in the range.

--
Regards,
Tom Ogilvy


"David" wrote in message
...
The following code returns 1 ,2 , 3, and 4 for the row
numbers of the non contiguous range rng.
Sub Code1 ()
Dim rng As Range
Set rng = Range("A1,A5,A7,A12")
For c = 1 To 4'
myArray(c) = rng.Cells(c).Row
Next
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Non Contiguous range and loops

David,

Try something like the following:

Dim Rng As Range
Dim Ar As Range
Dim C As Range
Set Rng = Range("A1,A5,A7,A12")

For Each Ar In Rng.Areas
For Each C In Ar
Debug.Print C.Row
Next C
Next Ar


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"David" wrote in message
...
The following code returns 1 ,2 , 3, and 4 for the row
numbers of the non contiguous range rng.
Sub Code1 ()
Dim rng As Range
Set rng = Range("A1,A5,A7,A12")
For c = 1 To 4'
myArray(c) = rng.Cells(c).Row
Next
End Sub






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
Formula to define non-contiguous range? Paul Martin[_2_] Excel Discussion (Misc queries) 7 July 3rd 09 02:51 AM
Join non-contiguous ranges into one range via named range? ker_01 Excel Discussion (Misc queries) 3 May 1st 09 11:09 AM
Non-Contiguous Named Range? Héctor Miguel Excel Discussion (Misc queries) 0 August 16th 08 06:22 AM
Non-contiguous named range JoeMNY Excel Discussion (Misc queries) 6 November 16th 07 07:39 PM
SUMIF non-contiguous range Lady_Olara Excel Worksheet Functions 13 January 10th 06 09:33 PM


All times are GMT +1. The time now is 01:25 PM.

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"