Gruß Gott
Codes 4
_ 2) Codes 4 shg maths Formulas Evaluate and VBA
From Post # 6
http://www.excelforum.com/tips-and-t...ml#post4214733
one can start with the formula in cell B4, and subsitute all Cell Address referrences with the actual formula in those cells to finally get a one line formula
Using Excel 2007
=IF(QUOTIENT(QUOTIENT(16384-1, 26)-1, 26)<>0,, CHAR(MOD(QUOTIENT(QUOTIENT(16384-1, 26)-1, 26)-1, 26) + 65), "") & IF(QUOTIENT(16384-1, 26)<>0, CHAR(MOD(QUOTIENT(16384-1, 26)-1, 26) + 65), "") & IF(16384<>0,, CHAR(MOD(16384-1, 26) + 65), "") & "" |
Allowing for use of a variable for the column of interest, lclm, along with some consideration of the use of Quotes in VBA,
http://www.excelfox.com/forum/f2/spe....html#post9517
http://www.mrexcel.com/forum/excel-q...ml#post4283381
gives us a string to be used in the VBA Evalute Method
strEval = "IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65), """") & IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """") & IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """""
and with some simplification to
strEval = "IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65)) & IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65)) & IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65))"
and finally a code of this form
Function FucshgMathsEval(ByVal lclm As Long) As String 'shg http://www.excelforum.com/tips-and-tutorials/1108643-vba-column-letter-from-column-number-explained.html#post4214733
' =WENN(QUOTIENT(QUOTIENT(16384-1; 26)-1; 26); ZEICHEN(REST(QUOTIENT(QUOTIENT(16384-1; 26)-1; 26)-1; 26) + 65); "") & WENN(QUOTIENT(16384-1; 26); ZEICHEN(REST(QUOTIENT(16384-1; 26)-1; 26) + 65); "") & WENN(16384; ZEICHEN(REST(16384-1; 26) + 65); "") & ""
' =IF(QUOTIENT(QUOTIENT(16384-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(16384-1, 26)-1, 26)-1, 26) + 65), "") & IF(QUOTIENT(16384-1, 26), CHAR(MOD(QUOTIENT(16384-1, 26)-1, 26) + 65), "") & IF(16384, CHAR(MOD(16384-1, 26) + 65), "") & ""
' Dim strEval As String: Let strEval = "IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65), " & """"") & IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """") & IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """""
' Let FucshgMathsEval = Evaluate("" & strEval & "")
' Let FucshgMathsEval = Evaluate("IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)<>0, CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65), " & """""" & ") & IF(QUOTIENT(" & lclm & "-1, 26)<>0, CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """") & IF(" & lclm & "<>0, CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """"")
Let FucshgMathsEval = Evaluate("IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65), " & """""" & ") & IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """") & IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """"")
End Function
_ .....................
Further The Evaluate formula can be written in a VBA Form
Function FucshgMathsVBA(ByVal lclm As Long) As String '
' Dim vtemp
' Let vtemp = IIf(((((lclm - 1) \ 26) - 1) \ 26) <> 0, Chr(65 + (((((lclm - 1) \ 26) - 1) \ 26) - 1 Mod 26)), "")
' Let vtemp = Evaluate("IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), 26)-1 + 65), """") ")
' Let vtemp = IIf(((lclm - 1) \ 26) <> 0, Chr(65 + (((lclm - 1) \ 26) - 1) Mod 26), "")
' Let vtemp = Evaluate("IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """")")
' Let vtemp = IIf(lclm <> 0, Chr(65 + (lclm - 1) Mod 26), "")
' Let vtemp = Evaluate("IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """"")
' Let FucshgMathsVBA = IIf(((((lclm - 1) \ 26) - 1) \ 26) <> 0, Chr(65 + (((((lclm - 1) \ 26) - 1) \ 26) - 1 Mod 26)), "") & IIf(((lclm - 1) \ 26) <> 0, Chr(65 + (((lclm - 1) \ 26) - 1) Mod 26), "") & IIf(lclm <> 0, Chr(65 + (lclm - 1) Mod 26), "")
Let FucshgMathsVBA = IIf(((((lclm - 1) \ 26) - 1) \ 26), Chr(65 + (((((lclm - 1) \ 26) - 1) \ 26) - 1 Mod 26)), "") & IIf(((lclm - 1) \ 26), Chr(65 + (((lclm - 1) \ 26) - 1) Mod 26), "") & IIf(lclm, Chr(65 + (lclm - 1) Mod 26), "")
' Let FucshgMathsVBA = Evaluate("IF(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26), CHAR(MOD(QUOTIENT(QUOTIENT(" & lclm & "-1, 26)-1, 26)-1, 26) + 65), """") & IF(QUOTIENT(" & lclm & "-1, 26), CHAR(MOD(QUOTIENT(" & lclm & "-1, 26)-1, 26) + 65), """") & IF(" & lclm & ", CHAR(MOD(" & lclm & "-1, 26) + 65), """") & """"")
End Function
_ ....................
Bookmarks