TRANSLATE User Defined Function

Location: http://www.mvps.org/dmcritchie/excel/translate.htm      
Home page: http://www.mvps.org/dmcritchie/excel/excel.htm
[View without Frames]

Simulate a mainframe type TRANSLATE function

some descriptive remarks here.
There is no TRANSLATE function to handle translating a table of characters to a different arrangement such as has been on mainframes.  Such usage has been around in mainframe computing 1960's to present.  Have never seen anything similar posted in VBA for Excel usage.  In PL/I and REXX it is Translate, expect it to be same in SAS, in Assembler it is XLAT, in COBOL it is TRANSFORM.  You can actually specify only the "to" string in REXX and the "from" string is the characters x'00 through x'FF (Helps to translate between EBCDIC and ASCII except that characters are not actually two way reversible).

A couple of references showing usage of the REXX Translate function are
  http://mitvma.mit.edu/cmshelp.cgi?REXX%20TRANSLAT%20(ALL and
  http://www.scoug.com/OPENHOUSE/REXXINTRO/RXBISTTR1.4.HTML

You would have to write your own User Defined Function.

  newString = translate(oldString, toString, fromString)
 Original Result toString  fromString
 abcdef AbCdEf ACE ace
 abcdefg aBcdefg aB Ab
 abcdefgh AbcDefgh DRATs drats
 Abcdefghijk Ayxwvughijk zyxwvu abcdef
 B2: =personal.xls!translate(A2,C2,D2)   
Function translate(oldString As String, toString As String, _
      fromString As String) As String
   'David McRitchie,  2005-03-08 programming
   ' http://groups.google.com/groups?threadm=5a3801c523d6%2496b31760%24a401280a%40phx.gbl
   'limited to equal length from and to strings for now
   'ref. http://mitvma.mit.edu/cmshelp.cgi?REXX%20TRANSLAT%20(ALL
   Dim i As Long, pos As Long, str As String
   str = ""
   For i = 1 To Len(oldString)
     '-- InStr([start,] haystack, needle [,compare])
     pos = InStr(1, fromString, Mid(oldString, i, 1), vbBinaryCompare)
     If pos = 0 Then
        str = str & Mid(oldString, i, 1)
     Else
        str = str & Mid(toString, pos, 1)   '-- corrected
     End If
   Next i
   translate = str
End Function

Google Beta Groups -- a lament (#googlebetagroups)

This topic has been incorporated into Remediation for Disastrous Google Beta Groups -- unfortuately there is not much remediation.

My correct posting of code was trashed by the Beta version on Google, compare the code above (or even Beta Groups own original view) with the discombobulated code at at Google Groups (Beta), and that the old version of google groups at google.uk.co is still useable.

Google apparently has an agenda to proprietize newsgroups and take owership of postings.  The one thing that makes threads unique in a posting is the message-id in your posting.  Google is once again trying to hide that and create their own identifier. 

The Google Beta groups has made a lot of things rather useless


Excel questions not directly concerning my web pages are best directed to newsgroups
such as news://msnews.microsoft.com/microsoft.public.excel.misc where Excel users all around the clock from at least 6 continents ask and answer Excel questions.  Posting suggestions and netiquette.  More information on newsgroups and searching newsgroups.    Google Groups (Usenet) Advanced Search Excel newsgroups (or search any newsgroup).
This page was introduced on March 08, 2005. 
[My Excel Pages -- home]    [INDEX to my site and the off-site pages I reference] 
[Site Search -- Excel]     [Go Back]    [Return to TOP

Please send your comments concerning this web page to: David McRitchie send email comments


Copyright © 1997 - 2005,  F. David McRitchie,  All Rights Reserved