MATLAB: How to delete an entire row from Excel from MATLAB

excel row delete shift matlab xlswrite

Ultimately I want to delete an entire row from an excel file (say, row 10) and shift the rows 11 onwards up so that there isn't an empty space in the file.
I can envisage a long winded solution to this using xlswrite to overwrite all the previous rows, but is there a simple solution to this? I can't find a way of doing it anywhere.
Many thanks!
Using R2016a

Best Answer

It's not hard to do in matlab if you know excel VBA. If you don't, it's just as easy to record a macro in excel and use that rather than trying to do it in matlab.
The following should work (untested since I don't have matlab installed on this machine):
file = 'C:\somewhere\somefile.xlsx';
sheet = 'Sheet1'; %can be name or numeric index
row = 10;
excel = actxserver('Excel.Application');
workbook = excel.Workbooks.Open(file);
worksheet = workbook.Worksheets.Item(sheet);
worksheet.Rows.Item(row).Delete;
workbook.Save;
excel.Quit;
Related Question