File Exchange

## Convert index to Excel A1 notation

version 1.0.0.0 (1.14 KB) by
Convert index to Excel A1 notation used in xlswrite

2 Downloads

Updated 21 Sep 2010

View License

This function translates an index to the Excel A1 notation that is used in xlswrite.

%%%
function a1String = idx2A1(idx)

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

if idx < 27
a1String = alphabet(idx);
else
idx2 = rem(idx,26);
if idx2 == 0
a1String = [alphabet(floor(idx/26)-1),'Z'];
else
a1String = [alphabet(floor(idx/26)),alphabet(idx2)];
end
end
%%%

### Cite As

Matt Brunner (2021). Convert index to Excel A1 notation (https://www.mathworks.com/matlabcentral/fileexchange/28794-convert-index-to-excel-a1-notation), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (1)

Erich

Your code has a maximum limit of 702 (ZZ). I modified it to accept arbitrarily larger inputs:

%%% convert index to A1 notation
function a1String = idx2A1(idx)

if idx > 16384
warning('Column number is larger than Excel limit.');
end

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

a1String = '';
while idx > 0
idx2 = rem(idx, 26);
if idx2 == 0
idx2 = 26;
idx = idx - 26;
end
a1String = [alphabet(idx2) a1String];
idx = floor(idx / 26);
end

##### MATLAB Release Compatibility
Created with R2007b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

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

Start Hunting!