Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Excel writing; next empty cell

255 views
Skip to first unread message

Mike

unread,
Apr 20, 2011, 4:27:05 PM4/20/11
to
Greetings all!

I have a program that calculates out several values and I want to write them to an Excel data sheet. However, I do not want the data to be overwritten. This is to be a log, so every time the program runs it needs to write to the next blank row.

The solutions I have seen are all for a single program run, and if you run the program again it overwrites the data from the previous run. A program that starts writing at A1 or similar is not what I am looking for.

So I am looking for a solution that will look into the Excel file I am writing into and determine what column is the first that is blank, and then write to that row. I can figure out the remaining data handling myself (hopefully!).

Any ideas, thoughts, or solutions? Any help is greatly appreciated!

-Michael

ImageAnalyst

unread,
Apr 20, 2011, 5:12:13 PM4/20/11
to
I believe you're going to have to ask Excel via ActiveX to do that. I
don't know off the top of my head how to find the last cell. You can
get some help by recording a macro in Excel and seeing what it
recorded.

Armindo

unread,
Apr 20, 2011, 5:17:05 PM4/20/11
to
You can read first the file and than count the rows using a variable size.
After that you ran write in the file in the right row.

example:

file directory
file = 'C:\Documents and Settings\desktop\rarb.xls'

% store data of file in variable a
a = xlsread(file);

% new data to write in file
t = ones(1,10)

% last row with data in the file
nRows = (size(a,1));

% plus 1 to write in the next line (if you have an header it should be + 2)
nRows = nRows +1;

% convert number to string
b = num2str(nRows)

% if you want to add data to the collum A you make concat strings
c = strcat('A', b)

% right to file the data t on the sheet Folha1 begining in the row c (e.g. A20)
xlswrite(file, t,'Folha1',c);

Jeremy

unread,
Apr 20, 2011, 5:29:04 PM4/20/11
to

Mike

unread,
Apr 25, 2011, 6:09:05 PM4/25/11
to
Thanks for the possible solutions, I will owrk on those and hopefully get somewhere with them.

Rbk

unread,
Jun 7, 2012, 8:16:07 AM6/7/12
to
"Armindo" wrote in message <ionigh$fin$1...@fred.mathworks.com>...
0 new messages