Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2013, 12:37 PM
Bananabean Bananabean is offline Macro to replace digits with letters Windows 7 64bit Macro to replace digits with letters Office 2010 64bit
Novice
Macro to replace digits with letters
 
Join Date: Sep 2013
Posts: 4
Bananabean is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 09-14-2013, 01:43 PM
gmaxey gmaxey is online now Macro to replace digits with letters Windows 7 32bit Macro to replace digits with letters Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 09-14-2013, 01:48 PM
Bananabean Bananabean is offline Macro to replace digits with letters Windows 7 64bit Macro to replace digits with letters Office 2010 64bit
Novice
Macro to replace digits with letters
 
Join Date: Sep 2013
Posts: 4
Bananabean is on a distinguished road
Default 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.
Reply With Quote
  #4  
Old 09-14-2013, 01:57 PM
gmaxey gmaxey is online now Macro to replace digits with letters Windows 7 32bit Macro to replace digits with letters Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 09-14-2013, 03:04 PM
Bananabean Bananabean is offline Macro to replace digits with letters Windows 7 64bit Macro to replace digits with letters Office 2010 64bit
Novice
Macro to replace digits with letters
 
Join Date: Sep 2013
Posts: 4
Bananabean is on a distinguished road
Default

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)
Reply With Quote
  #6  
Old 09-14-2013, 04:16 PM
gmaxey gmaxey is online now Macro to replace digits with letters Windows 7 32bit Macro to replace digits with letters Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 09-14-2013, 09:28 PM
Bananabean Bananabean is offline Macro to replace digits with letters Windows 7 64bit Macro to replace digits with letters Office 2010 64bit
Novice
Macro to replace digits with letters
 
Join Date: Sep 2013
Posts: 4
Bananabean is on a distinguished road
Default

Thank you very much, Greg. That is exactly what I wanted.
Reply With Quote
Reply



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
Macro to replace digits with letters Converts the words to actual All Capital Letters not workin macro?? powerdrum Word VBA 2 12-08-2011 05:06 PM
Macro to replace digits with letters Macro to Replace Fonts ballj_35 Word 3 05-10-2011 01:10 AM
Macro to replace digits with letters 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft