Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with retrieving the last cell in an excel sheet.

Status
Not open for further replies.

GeertVerhoeven

Technical User
Oct 7, 2001
142
BE
Hi all,

I'm having a problem with selecting the last filled cell from an excel worksheet. I've looked on the internet and found xlCellTypeLastCell. Unfortunately it doesn't work for me. I have a sheet with 10 items but it always selects only the first cell and not all the cells.

Does anyone have an idea (code is in C#).

Code I'm using:

Excel.Worksheet sheetSource = (Excel.Worksheet)workbook.Sheets[1];
Excel.Range range = sheetSource.get_Range("A1", sheetSource.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing));

int numberOfElements = range.Count; // Always 1 !!!!


Thanks in advance !

Geert
 
Have a look in the FAQ area of this forum: at least 2 ways to get last used cell.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'd test your inner construct ...
sheetSource.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing)

to see what Row it's pointing at, 'cos if that bit ain't working, you'll need a workaround.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top