I think I'm missing something....
UsedRange is a property of Worksheet, so if you can open the sheet, you can used UsedRange. The address of used range can be used both to determine the number of rows and columns and where they start.
From you example in R1C1 style:
UsedRange.Address(ReferenceStyle:=xlR1C1) = "R10C2:R509C21"
UsedRange.Rows.Count = 500
UsedRange.Columns.Count = 20
The UsedRange is intrinsically located.
Try:
Code:
(psuedo code)
OpenWorkbook
Dim MyRange as Range
Dim MyCell as Cell
Set MyRange = MySheet.UsedRange
For Each MyCell in MyRange
MsgBox Location MyCell.Address & " " & MyCell.Value
Next MyCell
This will cycle through all the cells in a range, by column, then row (i.e. A1, A2, A3, B1, B2, B3 ... etc)
If you want to 'locate yourself' within your used range use:
UsedRange.Cells(1,1)
this is the upper left corner of your range.
To traverse the range you can then use:
UsedRange.Cells(1,1).Offset(r,c)
Offset is a row and column offset from the original location.
It should also be relatively easy, knowing the bounds and location of your UsedRange, to construct subranges relating to rows and/or columns if necessary.
[Edited by Judd on 06-13-2000 at 06:52 AM]
Aha! You spotted the deliberate mistake ;)
I wrote 'Cell' but I meant 'Range', as you cleverly deduced....