Formula to convert number for number to letters
Convert Alphabet to number (a=1, b=2, etc.)
excel - Converting column letter to number - Stack Overflow
excel - Converting letters to numbers in VBA - Stack Overflow
Videos
The IF Function is the correct formula for this, You can achieve the result by using
=IF(A1="WT",0,IF(A1="AT",1,IF(A1="AB",2,""))))
provided that A1 is where your value is, you may then proceed to change the cell value to the corresponding cell in your sheet.
Another way to do it would be (assuming the school result is in A1)
=(SEARCH(A1,"WTATAB")-1)/2
This works as follows: SEARCH() looks for its first argument in its second argument, and returns the position (starting at 1). Thus, for any valid value (one of WT, AT, or AB) in A1, it will return 1, 3, or 5. We then subtract 1 from that result, giving 0, 2, or 4. That happens to be exactly twice the set of values we actually want, so we divide by 2, giving 0, 1 or 2.
You can reference columns by their letter like this:
Columns("A")
So to get the column number, just modify the above code like this:
Columns("A").Column
The above line returns an integer (1 in this case).
So if you were using the variable mycolumn to store and reference column numbers, you could set the value this way:
mycolumn = Sheets("Sheet1").Columns("A").Column
And then you could reference your variable this way:
Sheets("Sheet1").Columns(mycolumn)
or to reference a cell (A1):
Sheets("Sheet1").Cells(1,mycolumn)
or to reference a range of cells (A1:A10)you could use:
Sheets("Sheet1").Range(Cells(1,mycolumn),Cells(10,mycolumn))
The answer given may be simple but it is massively sub-optimal, because it requires getting a Range and querying a property. An optimal solution would be as follows:
Function getColIndex(sColRef As String) As Long
Dim sum As Long, iRefLen As Long
sum = 0: iRefLen = Len(sColRef)
For i = iRefLen To 1 Step -1
sum = sum + Base26(Mid(sColRef, i)) * 26 ^ (iRefLen - i)
Next
getColIndex = sum
End Function
Private Function Base26(sLetter As String) As Long
Base26 = Asc(UCase(sLetter)) - 64
End Function
Some examples:
getColIndex("A") '-->1
getColIndex("Z") '-->26
getColIndex("AA") '-->27
getColIndex("AZ") '-->52
getColIndex("AAA") '-->703
I think this UDF will work for you:
Option Explicit
Function ConvertLetterToNumber(ByVal strSource As String) As String
Dim i As Integer
Dim strResult As String
For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
Case 65 To 90:
strResult = strResult & Asc(Mid(strSource, i, 1)) - 64
Case Else
strResult = strResult & Mid(strSource, i, 1)
End Select
Next
ConvertLetterToNumber = strResult
End Function
It will convert each non-numeric value to its Ascii equivalent and then reduce it down to its alphabet equivalent (A=1, B=2, etc.). Just use it as a regular formula. NOTE: It assumes that your non-numeric values are upper case.
ADDENDUM
The code as stated above will return 250,000 rows in just under 2 minutes with a 4th Gen i5 processor and 8GB RAM.
Here, I wrote this. No range call required:
Function converttonumber(Column as string) As Long
Dim A As Integer, currentletter As String
converttonumber = 0
For A = 1 To Len(Column)
currentletter = Mid(Column, Len(Column) - A + 1, 1)
converttonumber = converttonumber + (Asc(currentletter) - 64) * 26 ^ (A - 1)
Next
End Function
Sub test()
Debug.Print converttonumber("AZ")
Debug.Print converttonumber("E")
Debug.Print converttonumber("AAA")
End Sub