writecell produces two cells when Range is a sigle cell

I am writing a since cell varialbe to an excel spreadsheet and the desired range changes each time. I decode the range as a selected Column (i.e., 'AX') concatenated to the row number i'm writing. Each time, the writecell produces the cell in the desired column and row, but also in the just previous column and row. The variable I'm writing is a single cell element. My code is:
Clm = cell2mat(ColmnName(jj));
Rng = [Clm num2str(irow)];
writecell(Cost,fnameout,'Sheet',1,'Range',Rng);
where, Clm = 'AE', irow = 31, Cost is a cell variable that changes each call, in this case Cost = 1×1 cell array / {[255.7800]}
writecell wrote to column AD and AE in row 31.

 Accepted Answer

Try this:
Rng = sprintf('%1$s%2$d:%1$s%2$d', ColmnName{jj}, irow);
writecell(Cost, fnameout, 'Sheet', 1, 'Range', Rng);
Learn how to use curly brace indexing, rather than relying on awkward CELL2MAT:

2 Comments

Yes, that did work.. Thank you.
Mike S
@Mike: i hope that it helped. To show your appreciation please remember to click the accept button.

Sign in to comment.

More Answers (0)

Products

Release

R2024a

Asked:

on 19 Jul 2026

Commented:

on 20 Jul 2026

Community Treasure Hunt

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

Start Hunting!