How to delete Multiple rows in excel file using activex
8 views (last 30 days)
Show older comments
Activesheet.Rows.Item(1).Delete;
the above line will delete first row in the active excel sheet. I want to delete multiple rows so I used the following line, but it did not work :
Activesheet.Rows.Item([1,2,5,64]).Delete;
0 Comments
Answers (1)
Bob Thompson
on 2 Feb 2018
You could try running a for loop:
rowstodelete = [1 2 5 64];
for i = 1:length(rowstodelete);
Activesheet.Rows.Item(i).Delete;
end
I know it's not the most efficient, but for some reason I can't seem to get away from my love of loops.
Alternatively, instead of using Item, you might try using Range (Activesheet.Rows.Range().Delete). I don't know if that will work as it's been a while since I used the ActiveX commands, and it may only work for consecutive rows, but it could be better than running through a loop every time you want to delete stuff.
0 Comments
See Also
Categories
Find more on ActiveX 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!