You can do this by dynamically creating the character string that you send to xlswrite to specify xl range.
Something like this:
>> firstRow = 1;
>> lastRow = 5;
>> firstCol = 'C';
>> lastCol = 'AY';
>> cellRange = [firstCol,num2str(firstRow),':',lastCol,num2str(lastRow)]
cellRange =
C1:AY5
The only thing left, is to figure out what "lastCol" is based on the column number. I wrote a function to do this myself a little while back. I know there are other versions floating around as well.
For example:
>> xlcolumnletter(51)
ans =
AY
Here's the code:
function colLetter = xlcolumnletter(colNumber)
if( colNumber > 26*27 )
error('XLCOLUMNLETTER: Requested column number is larger than 702. Need to revise method to work with 3 character columns');
else
atoz = char(65:90)';
singleChar = cellstr(atoz);
n = (1:26)';
indx = allcomb(n,n);
doubleChar = cellstr(atoz(indx));
xlLetters = [singleChar;doubleChar];
colLetter = xlLetters{colNumber};
end
Best Answer