Get First ColumnNumber of a Range

Jan 26, 2012 at 9: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? 

Coordinator
Jan 26, 2012 at 9:17 PM

Take your pick...

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

Jan 26, 2012 at 9:33 PM

That was too simple! Thanks! ;)

Feb 7, 2012 at 12:53 PM

Hello,

How to find it on an object of type NamedRange ?

Coordinator
Feb 7, 2012 at 3: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 6:19 AM

Thanks it works ;O)