Delete specific rows in excel

23 views (last 30 days)
Cristian Martin
Cristian Martin on 30 May 2022
Commented: dpb on 30 May 2022
I want to delete rows from an excel file before writte in to it, starting row no 9 till end. I want this for initialize a new file but to keep the first 8 rows for labels and other stuff. The file model is attached.
I tried many ways with no succes, including the one below:
data = xlsread(test.xlsx);
data(9, :) = [];
delete(test.xlsx); % So extra rows on the end of old worksheet don't stay there after writing new data.

Accepted Answer

dpb on 30 May 2022
Use read/writematrix instead
There are no builtin MATLAB functions that will read/return the textbox you've got stuck in that header region so you've got to blank out the other data that is in the file to do what you want with prepackaged functions.
Be a lot simpler to just create a template workbook and use it to create the new file from...
There are user-written functions on FEX and some have been posted here that use the ActiveX interface and package functions for some low-level operations such as this, but I don't have a specific link at hand...well, let's see -- I do have a utility package I did download some time back I've fiddled with some...let's see what's in it, I forget.
Excel = actxserver('Excel.Application')
Workbook = Excel.Workbooks.Open(fullfile(d.folder,
delete(Excel); clear Excel
is the basics -- I just used a hardcoded range; you'd have to figure that range out dynamically if not known a priori. There's a function that will return the used range in a sheet that could be used. To use ActiveX, one has to just pore through the VBA help files and find the functions of use and figure out what Excel syntax can be used w/ ActiveX; much that works in VBA doesn't translate over owing to there not being the VBA compiler to translate syntax.
dpb on 30 May 2022
The app has got to be able to know/find whatever file it's going to be writing to, so you'll have to have some way to determine that.
As far as the GUI, if you package an app, files that it needs are packaged with it so the template will be there.

Sign in to comment.

More Answers (0)


Find more on Data Import from MATLAB in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by