ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   C# programming - Getting number of last non-blank cell (column) in a row. (https://www.excelbanter.com/excel-programming/346956-c-programming-getting-number-last-non-blank-cell-column-row.html)

Paddy[_2_]

C# programming - Getting number of last non-blank cell (column) in a row.
 
I need to get the column number of the last non-blank cell in a row. I
am using the Excel Com object in a .NET app to get this done

I have something like this
Range rg = xSheet.get_Range("A1","A1"); // xSheet is the worksheet
object.
int lastColumnNumber = rg.Cells.....

I am not sure what the method call to do or the steps to follow.
Any help is appreciated,
- K.


Rowan Drummond[_2_]

C# programming - Getting number of last non-blank cell (column)in a row.
 
Not sure how you translate this into C# but in VBA it would be

lastColumnNumber = xsheet.cells(1,columns.count).end(xltoleft).column

Hope this helps
Rowan

Paddy wrote:
I need to get the column number of the last non-blank cell in a row. I
am using the Excel Com object in a .NET app to get this done

I have something like this
Range rg = xSheet.get_Range("A1","A1"); // xSheet is the worksheet
object.
int lastColumnNumber = rg.Cells.....

I am not sure what the method call to do or the steps to follow.
Any help is appreciated,
- K.


Paddy[_2_]

C# programming - Getting number of last non-blank cell (column) in a row.
 
Thanks but I was specifically looking for C# way to do this. The COM
API that is exposed to Visual Studio (i am referencing the Excel 9/10
COM object in my solution) does not explain the API nor the arguments
that are used.

So, I actually have xsheet.Cells but it is a property and I don't see
the sequence of method calls from there to get the last non-blank
column number.

- K


Rowan Drummond wrote:
Not sure how you translate this into C# but in VBA it would be

lastColumnNumber = xsheet.cells(1,columns.count).end(xltoleft).column

Hope this helps
Rowan

Paddy wrote:
I need to get the column number of the last non-blank cell in a row. I
am using the Excel Com object in a .NET app to get this done

I have something like this
Range rg = xSheet.get_Range("A1","A1"); // xSheet is the worksheet
object.
int lastColumnNumber = rg.Cells.....

I am not sure what the method call to do or the steps to follow.
Any help is appreciated,
- K.




All times are GMT +1. The time now is 04:21 PM.

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