Basic solution for a single letter column e.g. A to Z
=CODE(A1)-CODE("A")+1
Where A1 contains a capital letter representing a column reference between A and Z.
Basic solution for multi-letter column e.g. A, AA or AAA
For multi-letter columns we need to be a bit smarter. First in B1 (helper column) we "zero" pad so we can handle one, two and three letter columms:
=RIGHT(REPT(CHAR(CODE("A")-1),3)&A1, 3)
This extends references like A and AA to three character references @@A and @A. The "@" character has character code 64 (one below "A") and is thus equivalent to a column# of 0.
Now we take each character of the three character reference, substract the letter offset for "A" and multiply with 26^2, 26^1 and 26^0 respectively to get the column number in C1:
=(CODE(LEFT(B1,1))-CODE("A")+1)*26*26 + (CODE(MID(B1,2,1))-CODE("A")+1)*26 + (CODE(RIGHT(B1,1))-CODE("A")+1)
In Excel 365, you can do away with the helper column (B) by using LET, or rather use the faster array formula below.
Fast array formula solution for multi-letter references
The array version puts the three characters in an array, substracts the "A" character code, then multiply with a column vector {26^2; 26^1; 26^0}
=MMULT((CODE(MID(B1,{1,2,3},1))-CODE("A")+1),{676;26;1})
which combined with the zero-pad formula gives
=MMULT((CODE(MID(RIGHT(REPT(CHAR(CODE("A")-1),3)&A1, 3),{1,2,3},1))-CODE("A")+1),{676;26;1})
=COLUMN(<range>)
returns a number. Ex.=COLUMN(D1)
returns4