Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Anthony Slater
 
Posts: n/a
Default School-boy secret code help needed

Do you remember how we used to write secret code messages as kids whe -
A=1
B=2
C=3
D=4
etc...

So "How are you" would be written as "8,15,23 1,18,5 25,15,21"

Is there a way I could do this with excel where I would write the words in
separate cells and excel returns the corresponding numbers?

TIA
  #3   Report Post  
JE McGimpsey
 
Posts: n/a
Default

I think I'd use a User Defined Function instead:

Public Function SchoolBoy(sInput As String) As String
Dim nChars As Long
Dim i As Long
Dim sChar As String
Dim sTemp As String
nChars = Len(sInput)
If nChars = 0 Then
SchoolBoy = ""
Else
For i = 1 To nChars
sChar = UCase(Mid(sInput, i, 1))
If sChar Like "[A-Z]" Then
sTemp = sTemp & Asc(sChar) - 64 & ","
Else
If Right(sTemp, 1) = "," Then _
sTemp = Left(sTemp, Len(sTemp) - 1)
sTemp = sTemp & sChar
End If
Next i
SchoolBoy = Left(sTemp, Len(sTemp) + (Right(sTemp, 1) = ","))
End If
End Function

call as

=SchoolBoy(A1)

If you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm



In article ,
"Anthony Slater" wrote:

Do you remember how we used to write secret code messages as kids whe -
A=1
B=2
C=3
D=4
etc...

So "How are you" would be written as "8,15,23 1,18,5 25,15,21"

Is there a way I could do this with excel where I would write the words in
separate cells and excel returns the corresponding numbers?

TIA

  #4   Report Post  
Anthony Slater
 
Posts: n/a
Default

Thanks for your reply

I copied your code in to a new module in Personal.xls and returned to excel.

Am I right in thinking that my 'text' should be in cell A1 and then I enter
in another cell =SchoolBoy(a1)?

I tried this but it returned =#NAME?


"JE McGimpsey" wrote:

I think I'd use a User Defined Function instead:

Public Function SchoolBoy(sInput As String) As String
Dim nChars As Long
Dim i As Long
Dim sChar As String
Dim sTemp As String
nChars = Len(sInput)
If nChars = 0 Then
SchoolBoy = ""
Else
For i = 1 To nChars
sChar = UCase(Mid(sInput, i, 1))
If sChar Like "[A-Z]" Then
sTemp = sTemp & Asc(sChar) - 64 & ","
Else
If Right(sTemp, 1) = "," Then _
sTemp = Left(sTemp, Len(sTemp) - 1)
sTemp = sTemp & sChar
End If
Next i
SchoolBoy = Left(sTemp, Len(sTemp) + (Right(sTemp, 1) = ","))
End If
End Function

call as

=SchoolBoy(A1)

If you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm



In article ,
"Anthony Slater" wrote:

Do you remember how we used to write secret code messages as kids whe -
A=1
B=2
C=3
D=4
etc...

So "How are you" would be written as "8,15,23 1,18,5 25,15,21"

Is there a way I could do this with excel where I would write the words in
separate cells and excel returns the corresponding numbers?

TIA


  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

Try:

=personal.xls!schoolboy(a1)



Anthony Slater wrote:

Thanks for your reply

I copied your code in to a new module in Personal.xls and returned to excel.

Am I right in thinking that my 'text' should be in cell A1 and then I enter
in another cell =SchoolBoy(a1)?

I tried this but it returned =#NAME?

"JE McGimpsey" wrote:

I think I'd use a User Defined Function instead:

Public Function SchoolBoy(sInput As String) As String
Dim nChars As Long
Dim i As Long
Dim sChar As String
Dim sTemp As String
nChars = Len(sInput)
If nChars = 0 Then
SchoolBoy = ""
Else
For i = 1 To nChars
sChar = UCase(Mid(sInput, i, 1))
If sChar Like "[A-Z]" Then
sTemp = sTemp & Asc(sChar) - 64 & ","
Else
If Right(sTemp, 1) = "," Then _
sTemp = Left(sTemp, Len(sTemp) - 1)
sTemp = sTemp & sChar
End If
Next i
SchoolBoy = Left(sTemp, Len(sTemp) + (Right(sTemp, 1) = ","))
End If
End Function

call as

=SchoolBoy(A1)

If you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm



In article ,
"Anthony Slater" wrote:

Do you remember how we used to write secret code messages as kids whe -
A=1
B=2
C=3
D=4
etc...

So "How are you" would be written as "8,15,23 1,18,5 25,15,21"

Is there a way I could do this with excel where I would write the words in
separate cells and excel returns the corresponding numbers?

TIA



--

Dave Peterson


  #6   Report Post  
Anthony Slater
 
Posts: n/a
Default

Dave

Thanks, that worked a treat.

...and also a big thanks to JE McGimpsey for the excellent piece of code



"Dave Peterson" wrote:

Try:

=personal.xls!schoolboy(a1)



Anthony Slater wrote:

Thanks for your reply

I copied your code in to a new module in Personal.xls and returned to excel.

Am I right in thinking that my 'text' should be in cell A1 and then I enter
in another cell =SchoolBoy(a1)?

I tried this but it returned =#NAME?

"JE McGimpsey" wrote:

I think I'd use a User Defined Function instead:

Public Function SchoolBoy(sInput As String) As String
Dim nChars As Long
Dim i As Long
Dim sChar As String
Dim sTemp As String
nChars = Len(sInput)
If nChars = 0 Then
SchoolBoy = ""
Else
For i = 1 To nChars
sChar = UCase(Mid(sInput, i, 1))
If sChar Like "[A-Z]" Then
sTemp = sTemp & Asc(sChar) - 64 & ","
Else
If Right(sTemp, 1) = "," Then _
sTemp = Left(sTemp, Len(sTemp) - 1)
sTemp = sTemp & sChar
End If
Next i
SchoolBoy = Left(sTemp, Len(sTemp) + (Right(sTemp, 1) = ","))
End If
End Function

call as

=SchoolBoy(A1)

If you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm



In article ,
"Anthony Slater" wrote:

Do you remember how we used to write secret code messages as kids whe -
A=1
B=2
C=3
D=4
etc...

So "How are you" would be written as "8,15,23 1,18,5 25,15,21"

Is there a way I could do this with excel where I would write the words in
separate cells and excel returns the corresponding numbers?

TIA


--

Dave Peterson

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
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
formula / code help needed Paul Watkins Excel Discussion (Misc queries) 2 March 16th 05 08:27 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM
If statement needed Patsy Excel Worksheet Functions 1 November 4th 04 03:48 PM


All times are GMT +1. The time now is 08:30 PM.

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"