Re: replace characters by numbers

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Ogilvy (twogilvy_at_msn.com)
Date: 03/09/04


Date: Tue, 9 Mar 2004 08:30:19 -0500

That is a completely different problem. It may appear the same to you, but
in the context of the approach taken by both JE and myself, we took
advantage of the ascii value of the single character. A more general
approach would put a table on another worksheet such as
col a col b
AA 1
AB 2
BB 3
CA 4
RM 5

Name this Table Data1

then the code can be modified as:

   Public Sub LettersToNumbers()
        Dim rCell As Range
        Application.ScreenUpdating = False
        For Each rCell In Selection
            With rCell
               res = Application.Vlookup(.Value,Range("Data1"),2,0)
               if not iserror(res) then
                .Value = res
              End if
            End With
        Next rCell
        Application.ScreenUpdating = True
    End Sub

As long as your table includes entries for anything you will find in the
range you are processing (and its replacement value), then the above
approach will work (single letters, double letters, words, sentences,
numbers - mixes of these).

-- 
Regards,
Tom Ogilvy
"Michael E." <anonymous@discussions.microsoft.com> wrote in message
news:9177AC7D-0DDB-4706-B10F-56FB1000A18E@microsoft.com...
> Hi Tom,
>
> thank you very much. One question: sometimes the replacement logic is
different, in this case two characeters should be replaced by one numer,
e.g.((A2=2; B1=1; C6=4; D4=3). How do I have to change your macro?
>
> Kind regards
> Michael
>
>      ----- Tom Ogilvy wrote: -----
>
>         Public Sub LettersToNumbers()
>              Dim rCell As Range
>              vArr = Evaluate("{1,2;2,1;3,4;4,3}")
>              Application.ScreenUpdating = False
>              For Each rCell In Selection
>                  With rCell
>                      .Value = vArr(Asc(UCase(.Text)) - 64, 2)
>                  End With
>              Next rCell
>              Application.ScreenUpdating = True
>          End Sub
>
>      -- 
>      Regards,
>      Tom Ogilvy
>
>
>      "Michael E." <anonymous@discussions.microsoft.com> wrote in message
>      news:BC45F8F5-DB99-45AB-A88F-41C607291CA8@microsoft.com...
>      > I think a simple lookup table would do, because the replacement of
>      characters by numbers is mainly for statistic reasons. It would be of
great
>      help for me if you could include a lookup table (A=2; B=1; C=4; D=3)
in your
>      vba-macro.
>      >> Thanks a lot
>      > Michael
>      >>      ----- JE McGimpsey wrote: -----
>      >>      No - for that you'd need a lookup table or an algorithm. What
>      >      correlations do you expect to see?
>      >>>      In article
<8C517D4C-B6FA-4543-90CD-68E6D738E755@microsoft.com>,
>      >       "Michael E." <anonymous@discussions.microsoft.com> wrote:
>      >>> Thanks for the reply:
>      >> does the macro also work if the correlation between characters and
>      numbers is
>      >> different?
>      >> e.g.: A=2; B=1; C=4; D=3
>      >


Relevant Pages

  • Re: The Bug of ReadLine?
    ... Michael Harris ... I guess I wasn't clear on this, it seems to be corrupting the file on an NT ... > Given an ordinary ASCII text file (even one with some null characters ... the data is being corrupted when it is read by readline. ...
    (microsoft.public.scripting.vbscript)
  • Re: PIC P put to real use
    ... PICTURE and the INSPECT in such a case, because it's clearer in both ... characters being replaced as well as the replacement text! ... about the replacement of characters in a numeric-edited data item once its ... I actually like that better than the reference modification. ...
    (comp.lang.cobol)
  • Re: PIC P put to real use
    ... PICTURE and the INSPECT in such a case, because it's clearer in both ... characters being replaced as well as the replacement text! ... about the replacement of characters in a numeric-edited data item once its ... I actually like that better than the reference modification. ...
    (comp.lang.cobol)
  • Review: The Last Kiss (2006)
    ... A film review by Steve Rhodes ... THE LAST KISS, loosely adapted from an equally charming Italian film of the ... The characters are appealing, and the dialog is ... The story is really about Michael, ...
    (rec.arts.movies.reviews)
  • Review: The Last Kiss (*** 1/2)
    ... THE LAST KISS ... A film review by Steve Rhodes ... The characters are appealing, and the dialog is sharp and smart. ... The story is really about Michael, ...
    (misc.kids)