I'm trying to get the last row with data from a specific column and I'm getting the following error when running my code:
Unable to get the CountA property of the WorksheetFunction class
var xlApp = new Microsoft.Office.Interop.Excel.Application();
var wb = (Excel.Workbook)Globals.ThisAddIn.Application.ActiveWorkbook;
var wsConfig = wb.Sheets["Config"];
var usedRows = xlApp.WorksheetFunction.CountA(wsConfig.Columns[9]);
Also tried the following code, but returns:
Exception from HRESULT: 0x800A03EC
var usedRows = wsConfig.Range["I1", wsConfig.Cells[1, wsConfig.Rows.Count]].End(Excel.XlDirection.xlDown).Value;
Example:
Column I
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| |
=> usedRows = 5
because there are 5 rows with data on the column I