I need to convert a Google Spreadsheet column index into its corresponding letter value, for example, given a spreadsheet:
I need to do this (this function obviously does not exist, it's an example):
getColumnLetterByIndex(4); // this should return "D" getColumnLetterByIndex(1); // this should return "A" getColumnLetterByIndex(6); // this should return "F"
Now, I don't recall exactly if the index starts from 0
or from 1
, anyway the concept should be clear.
I didn't find anything about this on gas documentation.. am I blind? Any idea?
Thank you
If you have Professor Excel Tools already, you can simply use the =PROFEXColumn() function to return the column letter.
Do-While Loop is another way to convert column number to letter in VBA Excel. Similarly, call the UDF in the dataset, pass the cell reference number as the argument, press Enter and drag the row to convert the column number to letter in Excel with the Do-While Loop in VBA.
I wrote these a while back for various purposes (will return the double-letter column names for column numbers > 26):
function columnToLetter(column) { var temp, letter = ''; while (column > 0) { temp = (column - 1) % 26; letter = String.fromCharCode(temp + 65) + letter; column = (column - temp - 1) / 26; } return letter; } function letterToColumn(letter) { var column = 0, length = letter.length; for (var i = 0; i < length; i++) { column += (letter.charCodeAt(i) - 64) * Math.pow(26, length - i - 1); } return column; }
This works good
=REGEXEXTRACT(ADDRESS(ROW(); COLUMN()); "[A-Z]+")
even for columns beyond Z.
Simply replace COLUMN()
with your column number. The value of ROW()
doesn't matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With