![]() |
Coverting Alphabets into Numbers
I hope someone can help me with this.
I have a column of "encrypted" data (in excel), which needs to be converted. The data in each cell is "encrypted" by following this simple rule: A = 1 B = 2 C = 3 D = 4 E = 5 F = 6 G = 7 H = 8 I = 9 J =0 Therefore, if a cell has "BFDJ", the numerical value will be 2640. My problem is this: How can I take the sum of the "encrypted" data in the column to make a grand total, which is also encrypted using the above rule? I've looked around and it seems that there are functions which can change numbers into words, but not the other way round. Any assistance is much appreciated. |
Coverting Alphabets into Numbers
-Paste this code into a module
-Type, "BFDJ", into cell "A1" -Type, =Decode("A1"), in cell "A2" -Cell "A2" will return 2640 Regards, Dave Public Function DeCode(r As Variant) As Long Dim i As Integer, _ l As String For i = 1 To Len(r) l = l & GetValue(Mid(r, i, 1)) Next DeCode = l End Function Private Function GetValue(s As String) As String Select Case s Case Is < "J" GetValue = Asc(s) - 64 Case "J" GetValue = "0" End Select End Function |
Coverting Alphabets into Numbers
Try this function. It will give you the decoded total for any range of cells
you choose. =decodenum(A1:B5) Function decodenum(Target As Range) As Integer Total = 0 For Each cell In Target Subtotal = 0 For Count = 1 To Len(cell) Subtotal = (10 * Subtotal) + _ ((Asc(Mid(cell, Count, 1)) - Asc("A") + 1) Mod 10) Next Count Total = Total + Subtotal Next cell decodenum = Total End Function "Marcus" wrote: I hope someone can help me with this. I have a column of "encrypted" data (in excel), which needs to be converted. The data in each cell is "encrypted" by following this simple rule: A = 1 B = 2 C = 3 D = 4 E = 5 F = 6 G = 7 H = 8 I = 9 J =0 Therefore, if a cell has "BFDJ", the numerical value will be 2640. My problem is this: How can I take the sum of the "encrypted" data in the column to make a grand total, which is also encrypted using the above rule? I've looked around and it seems that there are functions which can change numbers into words, but not the other way round. Any assistance is much appreciated. |
Coverting Alphabets into Numbers
Marcus,
Not sure if this wil prove faster, but avoiding the Mid/Left etc text function in favour of maths (and 1 concatenation) is an alternative: Public Function DecodeString(EncodedStr As String) As Long Dim bytArray() As Byte Dim i As Long Dim OutStr As String Const ASCII_OFFSET As Long = 64 Const MAX_CODE As Long = 10 bytArray = UCase(EncodedStr) For i = LBound(bytArray) To UBound(bytArray) Step 2 bytArray(i) = bytArray(i) - ASCII_OFFSET If bytArray(i) = MAX_CODE Then bytArray(i) = 0 OutStr = OutStr & bytArray(i) Next DecodeString = CLng(OutStr) End Function NickHK "Marcus" wrote in message ... I hope someone can help me with this. I have a column of "encrypted" data (in excel), which needs to be converted. The data in each cell is "encrypted" by following this simple rule: A = 1 B = 2 C = 3 D = 4 E = 5 F = 6 G = 7 H = 8 I = 9 J =0 Therefore, if a cell has "BFDJ", the numerical value will be 2640. My problem is this: How can I take the sum of the "encrypted" data in the column to make a grand total, which is also encrypted using the above rule? I've looked around and it seems that there are functions which can change numbers into words, but not the other way round. Any assistance is much appreciated. |
Coverting Alphabets into Numbers
Thank you all. From the examples, I was also able to figure out how to
"encrypt" it back to alphabets. Thanks! "Joel" wrote: Try this function. It will give you the decoded total for any range of cells you choose. =decodenum(A1:B5) Function decodenum(Target As Range) As Integer Total = 0 For Each cell In Target Subtotal = 0 For Count = 1 To Len(cell) Subtotal = (10 * Subtotal) + _ ((Asc(Mid(cell, Count, 1)) - Asc("A") + 1) Mod 10) Next Count Total = Total + Subtotal Next cell decodenum = Total End Function "Marcus" wrote: I hope someone can help me with this. I have a column of "encrypted" data (in excel), which needs to be converted. The data in each cell is "encrypted" by following this simple rule: A = 1 B = 2 C = 3 D = 4 E = 5 F = 6 G = 7 H = 8 I = 9 J =0 Therefore, if a cell has "BFDJ", the numerical value will be 2640. My problem is this: How can I take the sum of the "encrypted" data in the column to make a grand total, which is also encrypted using the above rule? I've looked around and it seems that there are functions which can change numbers into words, but not the other way round. Any assistance is much appreciated. |
Coverting Alphabets into Numbers
Hello Marcus,
Just for the fun of it: If you like to decrypt via worksheet functions, I suggest to use =SUMPRODUCT(MOD(CODE(MID($A$1,ROW(INDIRECT("1:"&LE N($A$1))),1))-64,10), 10^(LEN($A$1)-ROW(INDIRECT("1:"&LEN($A$1))))) Regards, Bernd |
All times are GMT +1. The time now is 03:54 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com