Hello All,
I have a VBA code that I am moving to C#. For one of my scenario I have to identify last row number for column E , so that I can run loop for each row and read data in my C#.
Following was my working code in VBA: -
Dim mainWorkBook As Workbook
Set mainWorkBook = ActiveWorkbook
Dim rowCountSheet As Double
rowCountSheet = mainWorkBook.Sheets("Sheet7").Range("E1048576").End(xlUp).Row
For i = 12 To 12 + rowCount
'Read cells from each row and create a XML string
Next
My code in C#
int RowCount=0;
dynamic Excel = ExcelDnaUtil.Application;
try
{
RowCount = Excel.Worksheets["Reference"].Range("E1048576").End.Row;
MessageBox.Show("Row count is: " + RowCount);
}
finally {
MessageBox.Show("Row count is: " + RowCount);
}
I also tried these combination but it is not giving me desired result
Excel.Worksheets["Reference"].Range("E1048576").End(xlUp).Row //This gives error for xlUp
Excel.Worksheets["Reference"].Range("E1048576").RowLast // This gives 0
Please let me know how I can do so, or if you can guide me to some reference material for same.
Regards,
Ankit