r/excel • u/excelevator 3071 • Feb 14 '18
User Defined Function I've made the =MORSEC() function, converting any given string into morse code!
Blatantly stolen from this post and this code , a Morse Code generator.
Function MORSEC(command As String)
Dim i#, num#
Dim word As String
Dim MORSECAlpha() As String
MORSECAlpha = Split(".-,-...,-.-.,-..,.,..-.,--.,....,..,.---,-.-,.-..,--,-.,---,.--.,--.-,.-.,...,-,..-,...-,.--,-..-,-.--,--..,-----,.----,..---,...--,....-,.....,-....,--...,---..,----.,/,", ",")
MORSEC = ""
For i = 1 To Len(command)
num = Asc(UCase(Mid(command, i, 1))) - 65
If num >= 0 And num <= 25 Then
MORSEC = MORSEC & MORSECAlpha(num) & " "
ElseIf num >= -17 And num <= -8 Then
MORSEC = MORSEC & MORSECAlpha(num + 43) & " "
ElseIf num = -33 Then
MORSEC = MORSEC & MORSECAlpha(num + 69) & " "
End If
Next i
MORSEC = Trim(MORSEC)
End Function| Text | Morse Code |
|---|---|
| Excel morse | =morsec(A2) |
| Excel morse | . -..- -.-. . .-.. / -- --- .-. ... . |
edit: I was going to use unicode • ➖ but early versions Excel do not have the UNICHAR function and it would have been a bitch to implement as I look now!
edit2: implement word spacer as per this comment below
edit3: 20190716: 1 thru 9 code reversed for correct output. doh! thankyou u/Lapin3d
105
Upvotes
View all comments
Show parent comment
14
u/pancak3d 1189 Feb 14 '18
At last we can broadcast our spreadsheets via radio!