Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate Text into numbers and alphabets Sheeloo Excel Worksheet Functions 4 September 10th 08 11:49 AM
Numbers to Alphabets rk0909 Excel Discussion (Misc queries) 10 January 12th 08 11:38 AM
HOW TO CHAGE COLUMN ADDRESS FROM NUMBERS TO ALPHABETS koneru Excel Discussion (Misc queries) 2 January 9th 08 05:06 PM
how to change the alphabets to numbers and numbers to alphabets in Igneshwara reddy[_2_] Excel Worksheet Functions 2 September 20th 07 04:56 PM
columns showing numbers instead of alphabets inenewbl Excel Discussion (Misc queries) 1 January 26th 07 12:36 PM


All times are GMT +1. The time now is 07:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"