0

I am trying to write a macro function that returns the letter of the column number I am passing it. I thought I could use built-in Choose function but errors out. Below is a sample of what I tried:

function ReturnLetter (columnnumber) {

if (columnnumber < 27) {

return Choose(columnnumber, "a" , "b" , "c" .......);

} else if (columnnumber > 27 && columnnumber < 54) {

  return Choose(columnnumber, "aa" , "ab" , "ac" .......);

}}

Does anyone have any ideas?

player0
  • 124,011
  • 12
  • 67
  • 124
  • Does this answer your question? [Convert column index into corresponding column letter](https://stackoverflow.com/questions/21229180/convert-column-index-into-corresponding-column-letter) – TheMaster Mar 30 '20 at 05:27
  • Specifically, use [this answer](https://stackoverflow.com/a/53678158/) – TheMaster Mar 30 '20 at 05:27
  • As for your actual question, Use a simple array: `return ["a" , "b" , "c"][columnnumber-1]` – TheMaster Mar 30 '20 at 05:29
  • Although @TheMaster answer is good remember to check if the variable `columnumber` goes from 1 to the length of the array. But taking looking at your code maybe you just want to get the name of the column through the `columnnumber`, if that is the case there are simpler and more elegant solutions to do that in apps script, without needing to hardcode all the column names. Let me know if you actually want a solution for the former. – Raserhin Mar 30 '20 at 11:49

0 Answers0