ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return the row number of a cell relative to a range (https://www.excelbanter.com/excel-programming/338639-return-row-number-cell-relative-range.html)

Frederick Chow

Return the row number of a cell relative to a range
 
Hi all,

Is it possible to return the location of cell relative to a range, for
example, to return cell B3 as row 1 relative to range A3:B5? I found that
the RangeObj.Row property return only the absolute row number. thanks a lot.

Frederick Chow
Hong Kong.



Doug Glancy

Return the row number of a cell relative to a range
 
Frederick,

range("B3").row - (range("B3:c5").Rows(1).row + 1)

hth,

Doug

"Frederick Chow" wrote in message
...
Hi all,

Is it possible to return the location of cell relative to a range, for
example, to return cell B3 as row 1 relative to range A3:B5? I found that
the RangeObj.Row property return only the absolute row number. thanks a

lot.

Frederick Chow
Hong Kong.





Frederick Chow

Return the row number of a cell relative to a range
 
Dong,

Thanks for your quick response but I don't think your suggestion will work
for both Range("B3").Row and Range("B3:C5").Rows(1).Row return 3....

Frederick Chow
"Doug Glancy" wrote in message
...
Frederick,

range("B3").row - (range("B3:c5").Rows(1).row + 1)

hth,

Doug

"Frederick Chow" wrote in message
...
Hi all,

Is it possible to return the location of cell relative to a range, for
example, to return cell B3 as row 1 relative to range A3:B5? I found that
the RangeObj.Row property return only the absolute row number. thanks a

lot.

Frederick Chow
Hong Kong.







Doug Glancy

Return the row number of a cell relative to a range
 
Frederick,

I misplaced a parentheses. Should have been:

range("B3").row - (range("a3:c5").Rows(1).row) + 1

As you say they both return 3. That's why I subtracted one from the other
and added 1. Try typing it into the immediate window (Ctl-G in the VBE):

? range("B3").row - (range("B3:c5").Rows(1).row + 1)

and you'll see that it returns 1, which is what you wanted.

hth,

Doug

"Frederick Chow" wrote in message
...
Dong,

Thanks for your quick response but I don't think your suggestion will work
for both Range("B3").Row and Range("B3:C5").Rows(1).Row return 3....

Frederick Chow
"Doug Glancy" wrote in message
...
Frederick,

range("B3").row - (range("B3:c5").Rows(1).row + 1)

hth,

Doug

"Frederick Chow" wrote in message
...
Hi all,

Is it possible to return the location of cell relative to a range, for
example, to return cell B3 as row 1 relative to range A3:B5? I found

that
the RangeObj.Row property return only the absolute row number. thanks a

lot.

Frederick Chow
Hong Kong.










All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com