#1
|
|||
|
|||
Macro to replace digits with letters
I would like a macro to substitute letters for numbers (the integers from 0 to 25) in a selection; i.e. every instance of 25 becomes W, then every instance of 24 becomes L, then every instance of 23 becomes M and so on. How do I go about this, please? Clearly the 2 digit numbers must be replaced first, so the order of substitution matters. |
#2
|
|||
|
|||
And so on...? What does that mean. There is no logic in your question. W is the 22nd letter in the alphabet, L is the 12th and M is the 13th.
Are the numbers separated by spaces or what? Shoud the macro treat 1234 as a 1 a 2 a 3 and a 4 or a 12 then a 3 then a 4 or a 1 then a 23 then a 4? |
#3
|
|||
|
|||
Explanation
There are only numbers from 0 to 25 and they are replaced by a known permutation of the letters of the alphabet. In the example I changed 25 to W and so on.
|
#4
|
|||
|
|||
Replace numbers with letters of the alphabet e.g., 1 with A, 2 with B, 3 with C and so on. That makes sense. So if the number is 4 replace it with D if the number is 26 replace it with Z.
Your example makes no sense. Replace 25 with W, 24 with L, 23 with M. So what do you replace 22 with V (the 22nd letter) or N or A or what. How are the numbers separated? |
#5
|
|||
|
|||
The numbers are separated by operators like: 25 + 23 / 12 * 13 – 17
The numbers are coded which is why 1 is not necessarily A, 2 is not necessarily B and so on. Thus 25 + 23 / 12 * 13 – 17 might translate to W + M / B * C - N (or some other letter combination depending on the chosen code) |
#6
|
|||
|
|||
Code:
Sub DemoScratchMacro() 'A basic Word macro coded by Greg Maxey Dim arrFind() As String Dim arrReplace() As String Dim oRng As Word.Range Dim lngIndex As Long arrFind = Split("<25>|<24>|<23>|<22>|<21>|<20>|<19>|<18>|<17>|<16>|<15>|<14>|<13>|<12>|<11>|<10>|<9>|<8>|<7>|<6>|<5>|<4>|<3>|<2>|<1>|<0>", "|") arrReplace = Split("W|L|M|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?", "|") For lngIndex = 0 To UBound(arrFind) Set oRng = ActiveDocument.Range With oRng.Find .Text = arrFind(lngIndex) .MatchWildcards = True .Replacement.Text = arrReplace(lngIndex) .Execute Replace:=wdReplaceAll End With Next lngIndex End Sub |
#7
|
|||
|
|||
Thank you very much, Greg. That is exactly what I wanted.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Separate the digits into 3 combinations | Jasa P | Word VBA | 1 | 08-19-2012 11:04 PM |
Converts the words to actual All Capital Letters not workin macro?? | powerdrum | Word VBA | 2 | 12-08-2011 05:06 PM |
Macro to Replace Fonts | ballj_35 | Word | 3 | 05-10-2011 01:10 AM |
Problems merging in last 4 digits of an account higher than 16 digits | Glynda | Mail Merge | 1 | 04-08-2011 12:17 AM |
How to delete first 6 Digits and one Space from a CELL? | Learner7 | Excel | 3 | 08-10-2010 04:06 AM |