I was hoping that there is a better way to determine the name of the last column in varying ranges.
Dim iAlpha As Integer, fAlpha As Integer
Dim iRemainder As Integer, fRemainder As Integer
Dim ConvertToLetter As String
Dim fConvertToLetter As String
iAlpha = Int((DataLength) / 26) '26 for the letters
fAlpha = Int((DataLength + 2) / 26) 'for the average and sd functions, since they start at C not A
iRemainder = DataLength - (iAlpha * 26)
fRemainder = DataLength + 2 - (fAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
If fAlpha > 0 Then
fConvertToLetter = Chr(fAlpha + 64)
End If
If fRemainder > 0 Then
fConvertToLetter = fConvertToLetter & Chr(fRemainder + 64)
End If
This method works for one example of mine but not for the other. The one it works with has Datalength = 66
, which ends at BP
because there are two columns before the data starts. The example that doesn't work is Datalength = 120
, which ends at CZ
.