If the file is empty or contains data in only one line, it will .End('xlDown').Row;move to the very bottom of the sheet ( 1048576- this is the number of lines in the Excel 2007+ sheet).
Check if the cell is A2first empty, and return 0if there is one.
Or use the Upbottom of the sheet
num_rows = sheetObj.Cells(sheetObj.Rows.Count, 1).End('xlUp').Row
. Matlab,