View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Getting row indexes on Range

the Rows.Count property should return 3 as well

for what you need to do, I suggest a loop

dim cell as Range
dim text as string
FOR EACH cell in myRange
text = text & "," & cell.Row
NEXT

text will hold the address row

"Selsted" wrote:

(I refer to C# code, but answers in VB are welcome)

I have a Range in Excel, which includes several cells (the cells the user
selected in the Excel sheet). The range might include the following cells A2,
B7, G4. This means that the cells might not be connected.

If I look at myRange.Cells.Count, it will return 3. If I look at
myRange.Row, it will return 2 (if A2 was the first selected row by the user).

Now, I need to get the row numbers of all selected rows, so in the above
range, I need an int[] of {2, 7, 4}. But I can't see any solution to go
through the Cells and get the row index for the individual cell.