This project has moved and is read-only. For the latest updates, please go here.

Get First ColumnNumber of a Range

Jan 26, 2012 at 10:09 PM

How would I get the first columnNumber of a Range? 

I was able to see through the object hierarchy in the watch that a Range has RangeParameters > RangeAddress > FirstAddress > ColumnNumber
but I'm not sure how to obtain this through code. Is there a way? 

Jan 26, 2012 at 10:17 PM

Take your pick...

            range.RangeAddress.FirstAddress.ColumnNumber
            range.FirstColumn().ColumnNumber()
            range.FirstCell().Address.ColumnNumber
            range.FirstCell().WorksheetColumn().ColumnNumber()

Jan 26, 2012 at 10:33 PM

That was too simple! Thanks! ;)

Feb 7, 2012 at 1:53 PM

Hello,

How to find it on an object of type NamedRange ?

Feb 7, 2012 at 4:15 PM

Assuming the named range points to a single range:

     var range = worksheet.Range("YourNamedRange");

or

     var range = workbook.Range("YourNamedRange");

(depending on whether the named range has a worksheet or workbook scope)

Feb 8, 2012 at 7:19 AM

Thanks it works ;O)